This repository has been archived on 2022-08-19. You can view files and clone it, but cannot push or open issues or pull requests.
hydrogen-web/vite.config.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

const injectWebManifest = require("./scripts/build-plugins/manifest");
const injectServiceWorker = require("./scripts/build-plugins/service-worker");
2021-10-11 21:29:31 +05:30
const legacyBuild = require("./scripts/build-plugins/legacy-build");
const fs = require("fs");
const path = require("path");
2021-10-11 21:29:31 +05:30
// 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
const version = JSON.parse(fs.readFileSync(path.join(__dirname, "package.json"), "utf8")).version;
2021-10-11 21:29:31 +05:30
const {defineConfig} = require("vite");
let polyfillSrc;
let polyfillRef;
export default {
public: false,
root: "src/platform/web",
server: {
hmr: false
},
resolve: {
alias: {
"safe-buffer": "./scripts/package-overrides/safe-buffer/index.js",
2021-10-11 21:29:31 +05:30
"buffer": "./scripts/package-overrides/buffer/index.js",
}
2021-10-05 22:59:00 +05:30
},
build: {
outDir: "../../../target",
emptyOutDir: true,
2021-10-13 15:51:26 +05:30
minify: true,
2021-10-11 21:29:31 +05:30
sourcemap: false,
assetsInlineLimit: 0,
polyfillModulePreload: false,
},
plugins: [
2021-12-01 22:40:02 +05:30
// legacyBuild(scriptTagPath(path.join(__dirname, "src/platform/web/index.html"), 0), {
2021-12-01 18:36:15 +05:30
// "./Platform": "./LegacyPlatform"
// }, "hydrogen-legacy", [
// './legacy-polyfill',
// ]),
injectWebManifest("assets/manifest.json"),
2021-10-11 21:29:31 +05:30
injectServiceWorker("sw.js"),
],
define: {
"HYDROGEN_VERSION": JSON.stringify(version)
}
};
2021-12-01 22:40:02 +05:30
function scriptTagPath(htmlFile, index) {
return `${htmlFile}?html-proxy&index=${index}.js`;
}