2021-12-20 19:17:31 +01:00
|
|
|
const path = require("path");
|
2024-08-16 12:03:39 +02:00
|
|
|
const { defineConfig } = require("vite");
|
|
|
|
const mergeOptions = require("merge-options").bind({ concatArrays: true });
|
|
|
|
const { commonOptions } = require("./vite.common-config.js");
|
2021-12-21 15:28:55 +01:00
|
|
|
const manifest = require("./package.json");
|
2024-08-16 12:03:39 +02:00
|
|
|
const {
|
|
|
|
injectServiceWorker,
|
|
|
|
createPlaceholderValues,
|
|
|
|
} = require("./scripts/build-plugins/service-worker");
|
2021-12-20 19:17:31 +01:00
|
|
|
|
|
|
|
const externalDependencies = Object.keys(manifest.dependencies)
|
2021-12-21 15:28:55 +01:00
|
|
|
// just in case for safety in case fake-indexeddb wouldn't be
|
|
|
|
// treeshake'd out of the bundle
|
2021-12-20 19:17:31 +01:00
|
|
|
.concat(Object.keys(manifest.devDependencies))
|
2021-12-21 15:28:55 +01:00
|
|
|
// bundle bs58 because it uses buffer indirectly, which is a pain to bundle,
|
|
|
|
// so we don't annoy our library users with it.
|
2024-08-16 12:03:39 +02:00
|
|
|
.filter((d) => d !== "bs58");
|
2021-12-20 19:17:31 +01:00
|
|
|
|
2024-08-16 12:03:39 +02:00
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
const options = commonOptions(mode);
|
|
|
|
const definePlaceholders = createPlaceholderValues(mode);
|
|
|
|
return mergeOptions(options, {
|
|
|
|
root: "src/",
|
|
|
|
plugins: [
|
|
|
|
injectServiceWorker("./src/platform/web/sw.js", () => [], {
|
|
|
|
lib: {
|
|
|
|
DEFINE_GLOBAL_HASH: definePlaceholders.DEFINE_GLOBAL_HASH,
|
|
|
|
},
|
|
|
|
sw: definePlaceholders,
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
build: {
|
|
|
|
lib: {
|
|
|
|
entry: path.resolve(__dirname, "src/lib.ts"),
|
|
|
|
formats: ["cjs", "es"],
|
|
|
|
fileName: (format) => `hydrogen.${format}.js`,
|
|
|
|
},
|
|
|
|
minify: false,
|
|
|
|
sourcemap: false,
|
|
|
|
outDir: "../target/lib-build",
|
|
|
|
// don't bundle any dependencies, they should be imported/required
|
|
|
|
rollupOptions: {
|
|
|
|
external(id) {
|
|
|
|
return externalDependencies.some(
|
|
|
|
(d) => id === d || id.startsWith(d + "/")
|
|
|
|
);
|
|
|
|
},
|
2021-12-20 19:17:31 +01:00
|
|
|
},
|
2024-08-16 12:03:39 +02:00
|
|
|
},
|
|
|
|
});
|
2021-12-20 19:17:31 +01:00
|
|
|
});
|