2021-10-06 20:34:16 +02:00
|
|
|
const injectWebManifest = require("./scripts/build-plugins/manifest");
|
|
|
|
const injectServiceWorker = require("./scripts/build-plugins/service-worker");
|
2021-10-11 17:59:31 +02:00
|
|
|
const legacyBuild = require("./scripts/build-plugins/legacy-build");
|
2021-10-07 15:09:16 +02:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2021-10-11 17:59:31 +02:00
|
|
|
// we could also just import {version} from "../../package.json" where needed,
|
|
|
|
// but this won't work in the service worker yet as it is not transformed yet
|
|
|
|
// TODO: we should emit a chunk early on and then transform the asset again once we know all the other assets to cache
|
2021-10-07 15:09:16 +02:00
|
|
|
const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version;
|
2021-10-11 17:59:31 +02:00
|
|
|
const {defineConfig} = require("vite");
|
|
|
|
let polyfillSrc;
|
|
|
|
let polyfillRef;
|
2021-10-06 20:34:16 +02:00
|
|
|
|
2021-10-05 17:10:17 +02:00
|
|
|
export default {
|
|
|
|
public: false,
|
|
|
|
root: "src/platform/web",
|
|
|
|
server: {
|
|
|
|
hmr: false
|
2021-10-05 17:51:10 +02:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
"safe-buffer": "./scripts/package-overrides/safe-buffer/index.js",
|
2021-10-11 17:59:31 +02:00
|
|
|
"buffer": "./scripts/package-overrides/buffer/index.js",
|
2021-10-05 17:51:10 +02:00
|
|
|
}
|
2021-10-05 19:29:00 +02:00
|
|
|
},
|
|
|
|
build: {
|
|
|
|
outDir: "../../../target",
|
2021-10-06 20:34:16 +02:00
|
|
|
emptyOutDir: true,
|
2021-10-13 12:21:26 +02:00
|
|
|
minify: true,
|
2021-10-11 17:59:31 +02:00
|
|
|
sourcemap: false,
|
|
|
|
assetsInlineLimit: 0,
|
|
|
|
polyfillModulePreload: false,
|
2021-10-06 20:34:16 +02:00
|
|
|
},
|
|
|
|
plugins: [
|
2021-12-01 18:10:02 +01:00
|
|
|
// legacyBuild(scriptTagPath(path.join(__dirname, "src/platform/web/index.html"), 0), {
|
2021-12-01 14:06:15 +01:00
|
|
|
// "./Platform": "./LegacyPlatform"
|
|
|
|
// }, "hydrogen-legacy", [
|
|
|
|
// './legacy-polyfill',
|
|
|
|
// ]),
|
2021-10-06 20:34:16 +02:00
|
|
|
injectWebManifest("assets/manifest.json"),
|
2021-10-11 17:59:31 +02:00
|
|
|
injectServiceWorker("sw.js"),
|
2021-10-07 15:09:16 +02:00
|
|
|
],
|
|
|
|
define: {
|
|
|
|
"HYDROGEN_VERSION": JSON.stringify(version)
|
|
|
|
}
|
2021-10-05 17:10:17 +02:00
|
|
|
};
|
2021-12-01 18:10:02 +01:00
|
|
|
|
|
|
|
function scriptTagPath(htmlFile, index) {
|
|
|
|
return `${htmlFile}?html-proxy&index=${index}.js`;
|
|
|
|
}
|