2021-12-01 18:10:25 +01:00
|
|
|
const injectWebManifest = require("./scripts/build-plugins/manifest");
|
2021-12-09 16:37:31 +01:00
|
|
|
const {injectServiceWorker, createPlaceholderValues} = require("./scripts/build-plugins/service-worker");
|
2024-08-16 12:03:39 +02:00
|
|
|
const {
|
|
|
|
transformServiceWorkerInDevServer,
|
|
|
|
} = require("./scripts/build-plugins/sw-dev");
|
2022-04-11 12:55:28 +02:00
|
|
|
const themeBuilder = require("./scripts/build-plugins/rollup-plugin-build-themes");
|
2024-08-16 12:03:39 +02:00
|
|
|
const { defineConfig } = require("vite");
|
|
|
|
const mergeOptions = require("merge-options").bind({ concatArrays: true });
|
|
|
|
const { commonOptions, compiledVariables } = require("./vite.common-config.js");
|
2021-10-06 20:34:16 +02:00
|
|
|
|
2024-08-16 12:03:39 +02:00
|
|
|
export default defineConfig(({ mode }) => {
|
2021-12-09 16:37:31 +01:00
|
|
|
const definePlaceholders = createPlaceholderValues(mode);
|
2024-08-16 12:03:39 +02:00
|
|
|
const options = commonOptions(mode);
|
|
|
|
return mergeOptions(options, {
|
2021-12-09 16:37:31 +01:00
|
|
|
root: "src/platform/web",
|
|
|
|
base: "./",
|
2024-08-16 12:03:39 +02:00
|
|
|
publicDir: "./public",
|
2021-12-09 16:37:31 +01:00
|
|
|
build: {
|
|
|
|
outDir: "../../../target",
|
2021-12-17 14:28:25 +01:00
|
|
|
minify: true,
|
|
|
|
sourcemap: true,
|
2022-04-21 09:22:42 +02:00
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
2022-05-12 12:32:03 +02:00
|
|
|
assetFileNames: (asset) => {
|
|
|
|
if (asset.name.includes("config.json")) {
|
|
|
|
return "[name][extname]";
|
2024-08-16 12:03:39 +02:00
|
|
|
} else if (asset.name.match(/theme-.+\.json/)) {
|
2022-05-12 12:32:03 +02:00
|
|
|
return "assets/[name][extname]";
|
2024-08-16 12:03:39 +02:00
|
|
|
} else {
|
2022-05-12 12:32:03 +02:00
|
|
|
return "assets/[name].[hash][extname]";
|
|
|
|
}
|
2024-08-16 12:03:39 +02:00
|
|
|
},
|
2022-04-21 09:22:42 +02:00
|
|
|
},
|
|
|
|
},
|
2021-12-09 16:37:31 +01:00
|
|
|
},
|
|
|
|
plugins: [
|
2024-08-16 12:03:39 +02:00
|
|
|
transformServiceWorkerInDevServer(),
|
2022-04-13 10:54:50 +02:00
|
|
|
themeBuilder({
|
|
|
|
themeConfig: {
|
2022-06-23 11:36:22 +02:00
|
|
|
themes: ["./src/platform/web/ui/css/themes/element"],
|
2022-04-13 10:54:50 +02:00
|
|
|
default: "element",
|
|
|
|
},
|
2022-04-18 12:47:56 +02:00
|
|
|
compiledVariables,
|
2022-04-13 10:54:50 +02:00
|
|
|
}),
|
2021-12-09 16:37:31 +01:00
|
|
|
// important this comes before service worker
|
|
|
|
// otherwise the manifest and the icons it refers to won't be cached
|
|
|
|
injectWebManifest("assets/manifest.json"),
|
2024-08-16 12:03:39 +02:00
|
|
|
injectServiceWorker(
|
|
|
|
"./src/platform/web/sw.js",
|
|
|
|
findUnhashedFileNamesFromBundle,
|
|
|
|
{
|
|
|
|
// placeholders to replace at end of build by chunk name
|
|
|
|
index: {
|
|
|
|
DEFINE_GLOBAL_HASH:
|
|
|
|
definePlaceholders.DEFINE_GLOBAL_HASH,
|
|
|
|
},
|
|
|
|
sw: definePlaceholders,
|
|
|
|
}
|
|
|
|
),
|
2021-12-09 16:37:31 +01:00
|
|
|
],
|
2021-12-10 16:03:17 +01:00
|
|
|
});
|
2021-12-09 16:37:31 +01:00
|
|
|
});
|
2022-05-18 14:01:17 +02:00
|
|
|
|
|
|
|
function findUnhashedFileNamesFromBundle(bundle) {
|
|
|
|
const names = ["index.html"];
|
|
|
|
for (const fileName of Object.keys(bundle)) {
|
|
|
|
if (fileName.includes("config.json")) {
|
|
|
|
names.push(fileName);
|
|
|
|
}
|
|
|
|
if (/theme-.+\.json/.test(fileName)) {
|
|
|
|
names.push(fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return names;
|
|
|
|
}
|