vector-im-hydrogen-web/vite.config.js

51 lines
2.1 KiB
JavaScript
Raw Normal View History

const injectWebManifest = require("./scripts/build-plugins/manifest");
const {injectServiceWorker, createPlaceholderValues} = require("./scripts/build-plugins/service-worker");
2022-04-11 12:55:28 +02:00
const themeBuilder = require("./scripts/build-plugins/rollup-plugin-build-themes");
const {defineConfig} = require('vite');
const mergeOptions = require('merge-options').bind({concatArrays: true});
2022-04-11 12:55:28 +02:00
const {commonOptions, compiledVariables} = 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,
2022-04-21 09:22:42 +02:00
rollupOptions: {
output: {
assetFileNames: (asset) =>
asset.name.includes("config.json") ||
asset.name.match(/theme-.+\.json/)
? "assets/[name][extname]"
: "assets/[name].[hash][extname]",
2022-04-21 09:22:42 +02:00
},
},
},
plugins: [
2022-04-13 10:54:50 +02:00
themeBuilder({
themeConfig: {
themes: {
element: "./src/platform/web/ui/css/themes/element",
},
2022-04-13 10:54:50 +02:00
default: "element",
},
compiledVariables,
2022-04-13 10:54:50 +02:00
}),
// 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 12:12:49 +02:00
injectServiceWorker("./src/platform/web/sw.js", ["index.html", "assets/config.json", "assets/theme-element.json"], {
// placeholders to replace at end of build by chunk name
index: {
DEFINE_GLOBAL_HASH: definePlaceholders.DEFINE_GLOBAL_HASH,
},
sw: definePlaceholders,
}),
],
define: definePlaceholders,
});
});