dedupe output options

pull/8504/head
gtmnayan 3 years ago
parent 73d81b1ec7
commit da40e71f10

@ -42,7 +42,9 @@ export default [
index: "src/runtime/index.ts", index: "src/runtime/index.ts",
ssr: "src/runtime/ssr.ts", ssr: "src/runtime/ssr.ts",
}, },
output: ["esm", "cjs"].map((format) => { output: ["esm", "cjs"].map(
/** @returns {import('rollup').OutputOptions} */
(format) => {
const ext = format === "esm" ? "mjs" : "cjs"; const ext = format === "esm" ? "mjs" : "cjs";
return { return {
entryFileNames: (entry) => { entryFileNames: (entry) => {
@ -53,13 +55,17 @@ export default [
return `${entry.name}/index.${ext}`; return `${entry.name}/index.${ext}`;
} }
}, },
manualChunks: (id) => { manualChunks: (id) => {
if (id.endsWith("internal/index.ts")) return "internal"; if (id.endsWith("internal/index.ts")) {
return "internal";
}
}, },
format, format,
dir: ".", dir: ".",
}; };
}), }
),
plugins: [ plugins: [
replace({ replace({
preventAssignment: true, preventAssignment: true,
@ -67,19 +73,19 @@ export default [
__VERSION__: pkg.version, __VERSION__: pkg.version,
}, },
}), }),
,
ts_plugin, ts_plugin,
{ {
writeBundle(_options, bundle) { writeBundle(_options, bundle) {
for (const [_, entry] of Object.entries(bundle)) { for (const [_, entry] of Object.entries(bundle)) {
const dir = entry.name; const dir = entry.name;
if (!entry.isEntry || !runtime_entrypoints[dir]) continue; if (!entry.isEntry || !runtime_entrypoints[dir]) continue;
if (dir === "internal") { if (dir === "internal") {
const mod = bundle[`internal/index.mjs`]; const mod = bundle[`internal/index.mjs`];
if (mod) { if (mod) {
fs.writeFileSync( fs.writeFileSync(
"src/compiler/compile/internal_exports.ts", "src/compiler/compile/internal_exports.ts",
`// This file is automatically generated` + `// This file is automatically generated\n` +
`export default new Set(${JSON.stringify(mod.exports)});` `export default new Set(${JSON.stringify(mod.exports)});`
); );
} }
@ -89,7 +95,7 @@ export default [
`${dir}/package.json`, `${dir}/package.json`,
JSON.stringify( JSON.stringify(
{ {
main: "./index", main: "./index.cjs",
module: "./index.mjs", module: "./index.mjs",
types: "./index.d.ts", types: "./index.d.ts",
}, },

Loading…
Cancel
Save