2021-12-01 18:58:19 +01:00
|
|
|
const path = require("path");
|
2021-12-10 16:03:34 +01:00
|
|
|
const mergeOptions = require('merge-options').bind({concatArrays: true});
|
|
|
|
const commonOptions = require("./vite.common-config.js");
|
2021-12-01 18:58:19 +01:00
|
|
|
|
|
|
|
const srcDir = path.join(__dirname, "src/");
|
|
|
|
const modulesDir = path.join(srcDir, "node_modules/");
|
|
|
|
const mocksDir = path.join(srcDir, "mocks/");
|
|
|
|
const fixturesDir = path.join(srcDir, "fixtures/");
|
|
|
|
|
2021-12-10 16:03:34 +01:00
|
|
|
|
|
|
|
export default mergeOptions(commonOptions, {
|
2021-12-01 18:58:19 +01:00
|
|
|
root: "src/",
|
|
|
|
build: {
|
|
|
|
outDir: "../target",
|
|
|
|
lib: {
|
|
|
|
entry: "lib.ts",
|
2021-12-10 16:03:34 +01:00
|
|
|
fileName: "hydrogen",
|
2021-12-01 18:58:19 +01:00
|
|
|
formats: ["cjs", "es"]
|
|
|
|
},
|
|
|
|
rollupOptions: {
|
2021-12-10 16:03:34 +01:00
|
|
|
external: (id, parentId) => {
|
|
|
|
const resolveId = (id.startsWith("./") || id.startsWith("../")) ? path.join(path.dirname(parentId), id) : id;
|
|
|
|
return !resolveId.startsWith(srcDir) || resolveId.startsWith(mocksDir) || resolveId.startsWith(fixturesDir);
|
|
|
|
},
|
2021-12-01 18:58:19 +01:00
|
|
|
output: {
|
|
|
|
manualChunks: (id) => {
|
|
|
|
if (id.startsWith(srcDir)) {
|
|
|
|
const idPath = id.substring(srcDir.length);
|
|
|
|
const pathWithoutExt = idPath.substring(0, idPath.lastIndexOf("."));
|
|
|
|
return pathWithoutExt;
|
|
|
|
} else {
|
|
|
|
return "index";
|
|
|
|
}
|
|
|
|
},
|
|
|
|
chunkFileNames: `[format]/[name].js`,
|
2021-12-10 16:03:34 +01:00
|
|
|
// important to preserve export names of every module
|
|
|
|
// so we can still override the file and provider alternative impls
|
|
|
|
minifyInternalExports: false,
|
|
|
|
preferConst: true,
|
2021-12-01 18:58:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-12-10 16:03:34 +01:00
|
|
|
});
|