2021-12-01 22:40:25 +05:30
|
|
|
const cssvariables = require("postcss-css-variables");
|
|
|
|
const autoprefixer = require("autoprefixer");
|
|
|
|
const flexbugsFixes = require("postcss-flexbugs-fixes");
|
|
|
|
|
2021-10-07 18:39:16 +05:30
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2021-12-01 22:40:25 +05:30
|
|
|
|
|
|
|
const injectWebManifest = require("./scripts/build-plugins/manifest");
|
|
|
|
const injectServiceWorker = require("./scripts/build-plugins/service-worker");
|
|
|
|
// const legacyBuild = require("./scripts/build-plugins/legacy-build");
|
|
|
|
|
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
|
2021-10-07 18:39:16 +05:30
|
|
|
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;
|
2021-10-07 00:04:16 +05:30
|
|
|
|
2021-10-05 20:40:17 +05:30
|
|
|
export default {
|
|
|
|
public: false,
|
|
|
|
root: "src/platform/web",
|
2021-12-06 18:19:14 +05:30
|
|
|
base: "./",
|
2021-10-05 20:40:17 +05:30
|
|
|
server: {
|
|
|
|
hmr: false
|
2021-10-05 21:21:10 +05:30
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2021-12-01 22:41:01 +05:30
|
|
|
// these should only be imported by the base-x package in any runtime code
|
|
|
|
// and works in the browser with a Uint8Array shim,
|
|
|
|
// rather than including a ton of polyfill code
|
2021-10-05 21:21:10 +05:30
|
|
|
"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 21:21:10 +05:30
|
|
|
}
|
2021-10-05 22:59:00 +05:30
|
|
|
},
|
|
|
|
build: {
|
|
|
|
outDir: "../../../target",
|
2021-10-07 00:04:16 +05:30
|
|
|
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,
|
2021-10-07 00:04:16 +05:30
|
|
|
},
|
|
|
|
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',
|
|
|
|
// ]),
|
2021-12-06 19:55:44 +05:30
|
|
|
// important this comes before service worker
|
|
|
|
// otherwise the manifest and the icons it refers to won't be cached
|
2021-10-07 00:04:16 +05:30
|
|
|
injectWebManifest("assets/manifest.json"),
|
2021-10-11 21:29:31 +05:30
|
|
|
injectServiceWorker("sw.js"),
|
2021-10-07 18:39:16 +05:30
|
|
|
],
|
|
|
|
define: {
|
|
|
|
"HYDROGEN_VERSION": JSON.stringify(version)
|
2021-12-01 22:40:25 +05:30
|
|
|
},
|
|
|
|
css: {
|
|
|
|
postcss: {
|
|
|
|
plugins: [
|
|
|
|
cssvariables({
|
|
|
|
preserve: (declaration) => {
|
|
|
|
return declaration.value.indexOf("var(--ios-") == 0;
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
// the grid option creates some source fragment that causes the vite warning reporter to crash because
|
|
|
|
// it wants to log a warning on a line that does not exist in the source fragment.
|
|
|
|
// autoprefixer({overrideBrowserslist: ["IE 11"], grid: "no-autoplace"}),
|
|
|
|
flexbugsFixes()
|
|
|
|
]
|
|
|
|
}
|
2021-10-07 18:39:16 +05:30
|
|
|
}
|
2021-10-05 20:40:17 +05:30
|
|
|
};
|
2021-12-01 22:40:02 +05:30
|
|
|
|
|
|
|
function scriptTagPath(htmlFile, index) {
|
|
|
|
return `${htmlFile}?html-proxy&index=${index}.js`;
|
|
|
|
}
|