3bee4b4585
bs58 depends on safe-buffer, which depends on buffer, which is a bit of a pain to bundle as it is a built-in node module. You'd typically replace buffer with a browser polyfill in your build system but: a) this is somewhat a pain to setup for simple apps b) the polyfill is way more than we need (6kb), so we prefer to bundle our minimal buffer replacement that uses Uint8Array. Since it is a transitive dependency, we need to bundle bs58 and all of its transitive dependencies (2.5kb) as well, so if users of hydrogen-sdk also use any of these, they'll be double included in their bundle.
29 lines
1.2 KiB
JavaScript
29 lines
1.2 KiB
JavaScript
const injectWebManifest = require("./scripts/build-plugins/manifest");
|
|
const {injectServiceWorker, createPlaceholderValues} = require("./scripts/build-plugins/service-worker");
|
|
const {defineConfig} = require('vite');
|
|
const mergeOptions = require('merge-options').bind({concatArrays: true});
|
|
const commonOptions = require("./vite.common-config.js");
|
|
|
|
export default defineConfig(({mode}) => {
|
|
const definePlaceholders = createPlaceholderValues(mode);
|
|
return mergeOptions(commonOptions, {
|
|
root: "src/platform/web",
|
|
base: "./",
|
|
build: {
|
|
outDir: "../../../target",
|
|
minify: true,
|
|
sourcemap: true,
|
|
},
|
|
plugins: [
|
|
// important this comes before service worker
|
|
// otherwise the manifest and the icons it refers to won't be cached
|
|
injectWebManifest("assets/manifest.json"),
|
|
injectServiceWorker("./src/platform/web/sw.js", ["index.html"], {
|
|
// placeholders to replace at end of build by chunk name
|
|
"index": {DEFINE_GLOBAL_HASH: definePlaceholders.DEFINE_GLOBAL_HASH},
|
|
"sw": definePlaceholders
|
|
}),
|
|
],
|
|
define: definePlaceholders,
|
|
});
|
|
});
|