2024-08-16 12:03:39 +02:00
|
|
|
const {
|
|
|
|
createPlaceholderValues,
|
|
|
|
} = require("./scripts/build-plugins/service-worker");
|
2021-12-10 16:03:17 +01:00
|
|
|
const flexbugsFixes = require("postcss-flexbugs-fixes");
|
2022-04-11 12:55:28 +02:00
|
|
|
const compileVariables = require("./scripts/postcss/css-compile-variables");
|
|
|
|
const urlVariables = require("./scripts/postcss/css-url-to-variables");
|
|
|
|
const urlProcessor = require("./scripts/postcss/css-url-processor");
|
2024-08-16 12:03:39 +02:00
|
|
|
const appManifest = require("./package.json");
|
|
|
|
const sdkManifest = require("./scripts/sdk/base-manifest.json");
|
2022-04-11 12:55:28 +02:00
|
|
|
const compiledVariables = new Map();
|
2024-08-16 12:03:39 +02:00
|
|
|
import { buildColorizedSVG as replacer } from "./scripts/postcss/svg-builder.mjs";
|
|
|
|
import { derive } from "./src/platform/web/theming/shared/color.mjs";
|
2021-12-10 16:03:17 +01:00
|
|
|
|
2024-08-16 12:03:39 +02:00
|
|
|
const commonOptions = (mode) => {
|
|
|
|
const definePlaceholders = createPlaceholderValues(mode);
|
|
|
|
return {
|
|
|
|
logLevel: "warn",
|
|
|
|
publicDir: false,
|
|
|
|
server: {
|
|
|
|
hmr: false,
|
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
// 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
|
|
|
|
"safe-buffer":
|
|
|
|
"./scripts/package-overrides/safe-buffer/index.js",
|
|
|
|
buffer: "./scripts/package-overrides/buffer/index.js",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
build: {
|
|
|
|
emptyOutDir: true,
|
|
|
|
assetsInlineLimit: 0,
|
|
|
|
polyfillModulePreload: false,
|
|
|
|
},
|
|
|
|
assetsInclude: ["**/config.json"],
|
|
|
|
define: Object.assign(
|
|
|
|
{
|
|
|
|
DEFINE_VERSION: `"${getVersion(mode)}"`,
|
|
|
|
DEFINE_GLOBAL_HASH: JSON.stringify(null),
|
|
|
|
DEFINE_IS_SDK: mode === "sdk" ? "true" : "false",
|
|
|
|
DEFINE_PROJECT_DIR: JSON.stringify(__dirname),
|
|
|
|
},
|
|
|
|
definePlaceholders
|
|
|
|
),
|
|
|
|
css: {
|
|
|
|
postcss: {
|
|
|
|
plugins: [
|
|
|
|
compileVariables({ derive, compiledVariables }),
|
|
|
|
urlVariables({ compiledVariables }),
|
|
|
|
urlProcessor({ replacer }),
|
|
|
|
flexbugsFixes(),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2021-12-10 16:03:17 +01:00
|
|
|
};
|
|
|
|
|
2024-08-16 12:03:39 +02:00
|
|
|
/**
|
|
|
|
* Get the version for this build
|
|
|
|
* @param mode Vite mode for this build
|
|
|
|
* @returns string representing version
|
|
|
|
*/
|
|
|
|
function getVersion(mode) {
|
|
|
|
if (mode === "production") {
|
|
|
|
// This is an app build, so return the version from root/package.json
|
|
|
|
return appManifest.version;
|
|
|
|
} else if (mode === "sdk") {
|
|
|
|
// For the sdk build, return version from base-manifest.json
|
|
|
|
return sdkManifest.version;
|
|
|
|
} else {
|
|
|
|
// For the develop server
|
|
|
|
return "develop";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 12:55:28 +02:00
|
|
|
module.exports = { commonOptions, compiledVariables };
|