2023-07-17 14:36:05 +00:00
|
|
|
import { defineConfig } from "vite";
|
|
|
|
import optimizer from "vite-plugin-optimizer";
|
|
|
|
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
|
|
|
import { resolve } from "path";
|
|
|
|
|
|
|
|
const config = {};
|
|
|
|
|
|
|
|
["background", "bootloader", "bridge", "crypto", "cryptoLoader"].forEach(
|
|
|
|
(item) => {
|
|
|
|
config[item] = {
|
|
|
|
entry: resolve(__dirname, `./src/main/${item}.ts`),
|
2023-07-17 16:25:42 +00:00
|
|
|
fileName: item,
|
2023-07-17 14:36:05 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-07-17 15:38:16 +00:00
|
|
|
const currentConfig = config[process.env.LIB_NAME];
|
|
|
|
if (currentConfig === undefined) {
|
|
|
|
throw new Error("LIB_NAME is not defined or is not valid");
|
|
|
|
}
|
|
|
|
|
2023-07-17 14:36:05 +00:00
|
|
|
export default defineConfig({
|
|
|
|
build: {
|
|
|
|
outDir: "lib",
|
2023-07-17 16:26:21 +00:00
|
|
|
emptyOutDir: false,
|
2023-07-17 14:36:05 +00:00
|
|
|
lib: {
|
2023-07-18 04:34:30 +00:00
|
|
|
formats: ["umd"],
|
2023-07-17 14:36:05 +00:00
|
|
|
...currentConfig,
|
2023-07-17 17:41:04 +00:00
|
|
|
name: currentConfig.fileName,
|
2023-07-17 14:36:05 +00:00
|
|
|
},
|
|
|
|
minify: false,
|
|
|
|
rollupOptions: { output: { inlineDynamicImports: true } },
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
dedupe: ["@lumeweb/libportal", "@lumeweb/libweb", "@lumeweb/libkernel"],
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
optimizer({
|
|
|
|
"node-fetch":
|
|
|
|
"const e = undefined; export default e;export {e as Response, e as FormData, e as Blob};",
|
|
|
|
}),
|
|
|
|
nodePolyfills({
|
|
|
|
exclude: ["fs"],
|
|
|
|
globals: { Buffer: true, global: true, process: true },
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|