2021-12-01 22:40:25 +05:30
|
|
|
const injectWebManifest = require("./scripts/build-plugins/manifest");
|
2021-12-09 21:07:31 +05:30
|
|
|
const {injectServiceWorker, createPlaceholderValues} = require("./scripts/build-plugins/service-worker");
|
2022-04-11 16:25:28 +05:30
|
|
|
const themeBuilder = require("./scripts/build-plugins/rollup-plugin-build-themes");
|
2021-12-09 21:07:31 +05:30
|
|
|
const {defineConfig} = require('vite');
|
2021-12-10 20:33:17 +05:30
|
|
|
const mergeOptions = require('merge-options').bind({concatArrays: true});
|
2022-04-11 16:25:28 +05:30
|
|
|
const {commonOptions, compiledVariables} = require("./vite.common-config.js");
|
2021-10-07 00:04:16 +05:30
|
|
|
|
2021-12-09 21:07:31 +05:30
|
|
|
export default defineConfig(({mode}) => {
|
|
|
|
const definePlaceholders = createPlaceholderValues(mode);
|
2021-12-10 20:33:17 +05:30
|
|
|
return mergeOptions(commonOptions, {
|
2021-12-09 21:07:31 +05:30
|
|
|
root: "src/platform/web",
|
|
|
|
base: "./",
|
|
|
|
build: {
|
|
|
|
outDir: "../../../target",
|
2021-12-17 18:58:25 +05:30
|
|
|
minify: true,
|
|
|
|
sourcemap: true,
|
2022-04-21 12:52:42 +05:30
|
|
|
rollupOptions: {
|
|
|
|
output: {
|
2022-04-18 16:17:56 +05:30
|
|
|
assetFileNames: (asset) =>
|
|
|
|
asset.name.includes("config.json") ||
|
|
|
|
asset.name.match(/theme-.+\.json/)
|
|
|
|
? "assets/[name][extname]"
|
|
|
|
: "assets/[name].[hash][extname]",
|
2022-04-21 12:52:42 +05:30
|
|
|
},
|
|
|
|
},
|
2021-12-09 21:07:31 +05:30
|
|
|
},
|
|
|
|
plugins: [
|
2022-04-13 14:24:50 +05:30
|
|
|
themeBuilder({
|
|
|
|
themeConfig: {
|
2022-04-18 16:17:56 +05:30
|
|
|
themes: {
|
|
|
|
element: "./src/platform/web/ui/css/themes/element",
|
|
|
|
},
|
2022-04-13 14:24:50 +05:30
|
|
|
default: "element",
|
|
|
|
},
|
2022-04-18 16:17:56 +05:30
|
|
|
compiledVariables,
|
2022-04-13 14:24:50 +05:30
|
|
|
}),
|
2021-12-09 21:07:31 +05:30
|
|
|
// important this comes before service worker
|
|
|
|
// otherwise the manifest and the icons it refers to won't be cached
|
|
|
|
injectWebManifest("assets/manifest.json"),
|
2022-05-18 17:31:17 +05:30
|
|
|
injectServiceWorker("./src/platform/web/sw.js", findUnhashedFileNamesFromBundle, {
|
2021-12-09 21:07:31 +05:30
|
|
|
// placeholders to replace at end of build by chunk name
|
2022-04-18 16:17:56 +05:30
|
|
|
index: {
|
|
|
|
DEFINE_GLOBAL_HASH: definePlaceholders.DEFINE_GLOBAL_HASH,
|
|
|
|
},
|
|
|
|
sw: definePlaceholders,
|
2021-12-09 21:07:31 +05:30
|
|
|
}),
|
|
|
|
],
|
2021-12-10 20:33:17 +05:30
|
|
|
define: definePlaceholders,
|
|
|
|
});
|
2021-12-09 21:07:31 +05:30
|
|
|
});
|
2022-05-18 17:31:17 +05:30
|
|
|
|
|
|
|
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;
|
|
|
|
}
|