Skip to content

Commit 847769e

Browse files
committed
fix: make ReactiveFlags able to treeshake in esm
1 parent decaf12 commit 847769e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

build.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,13 @@ cjsProgram.emit(undefined, (fileName, text) => {
5454
esmProgram.emit(undefined, (fileName, text) => {
5555
fileName = fileName.slice(0, -'.js'.length) + '.mjs';
5656
text = text.replace(/\.\/system\.js/g, './system.mjs');
57+
text = text.replace(
58+
`var ReactiveFlags;\n(function (ReactiveFlags)`,
59+
`var ReactiveFlags = /*#__PURE__*/(function (ReactiveFlags = {})`,
60+
);
61+
text = text.replace(
62+
`})(ReactiveFlags || (ReactiveFlags = {}));`,
63+
` return ReactiveFlags;\n})();`,
64+
)
5765
ts.sys.writeFile(fileName, text);
5866
});

size.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ require('./build.js');
33
const rolldown = require('rolldown');
44

55
rolldown.build({
6-
input: 'esm/index.mjs', output: { minify: true }, write: false
6+
input: 'esm/index.mjs', output: { minify: true }, write: false, treeshake: true
77
}).then(built => {
88
console.log(`esm/index.mjs: ${(built.output[0].code.length / 1024).toFixed(2)} KB`);
99
});
1010
rolldown.build({
11-
input: 'esm/system.mjs', output: { minify: true }, write: false
11+
input: 'esm/system.mjs', output: { minify: true }, write: false, treeshake: true
1212
}).then(built => {
1313
console.log(`esm/system.mjs: ${(built.output[0].code.length / 1024).toFixed(2)} KB`);
1414
});
15-
rolldown.build({ input: 'cjs/index.cjs', output: { minify: true }, write: false }).then(built => {
15+
rolldown.build({
16+
input: 'cjs/index.cjs', output: { minify: true }, write: false, treeshake: true
17+
}).then(built => {
1618
console.log(`cjs/index.cjs: ${(built.output[0].code.length / 1024).toFixed(2)} KB`);
1719
});
18-
rolldown.build({ input: 'cjs/system.cjs', output: { minify: true }, write: false }).then(built => {
20+
rolldown.build({
21+
input: 'cjs/system.cjs', output: { minify: true }, write: false, treeshake: true
22+
}).then(built => {
1923
console.log(`cjs/system.cjs: ${(built.output[0].code.length / 1024).toFixed(2)} KB`);
2024
});

0 commit comments

Comments
 (0)