Skip to content

Commit 024df60

Browse files
build: disable hoistTransitiveImports for better tree shake (#3146)
1 parent f779188 commit 024df60

File tree

9 files changed

+80
-35
lines changed

9 files changed

+80
-35
lines changed

.changeset/popular-pillows-draw.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@module-federation/webpack-bundler-runtime': patch
3+
'@module-federation/data-prefetch': patch
4+
'@module-federation/runtime-tools': patch
5+
'@module-federation/managers': patch
6+
'@module-federation/manifest': patch
7+
'@module-federation/runtime': patch
8+
'@module-federation/sdk': patch
9+
---
10+
11+
disable hoistTransitiveImports for better tree shake

packages/data-prefetch/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = (rollupConfig, _projectOptions) => {
2828
return 'polyfills';
2929
}
3030
},
31+
hoistTransitiveImports: false,
3132
}));
3233
} else {
3334
rollupConfig.output = {
@@ -37,6 +38,7 @@ module.exports = (rollupConfig, _projectOptions) => {
3738
return 'polyfills';
3839
}
3940
},
41+
hoistTransitiveImports: false,
4042
};
4143
}
4244

packages/managers/rollup.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,15 @@ module.exports = (rollupConfig, _projectOptions) => {
99
}),
1010
);
1111

12+
// Check if rollupConfig.output is an array
13+
if (Array.isArray(rollupConfig.output)) {
14+
rollupConfig.output.forEach((output) => {
15+
output.hoistTransitiveImports = false;
16+
});
17+
} else if (rollupConfig.output) {
18+
// If it's not an array, directly set the property
19+
rollupConfig.output.hoistTransitiveImports = false;
20+
}
21+
1222
return rollupConfig;
1323
};

packages/manifest/rollup.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
const copy = require('rollup-plugin-copy');
22

33
module.exports = (rollupConfig, _projectOptions) => {
4+
// Check if rollupConfig.output is an array
5+
if (Array.isArray(rollupConfig.output)) {
6+
rollupConfig.output.forEach((output) => {
7+
output.hoistTransitiveImports = false;
8+
});
9+
} else if (rollupConfig.output) {
10+
// If it's not an array, directly set the property
11+
rollupConfig.output.hoistTransitiveImports = false;
12+
}
13+
414
rollupConfig.plugins.push(
515
copy({
616
targets: [

packages/runtime-tools/rollup.config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,18 @@ module.exports = (rollupConfig) => {
66
'packages/runtime-tools/src/webpack-bundler-runtime.ts',
77
};
88

9+
// Check if output is an array and add hoistTransitiveImports: false
10+
if (Array.isArray(rollupConfig.output)) {
11+
rollupConfig.output = rollupConfig.output.map((c) => ({
12+
...c,
13+
hoistTransitiveImports: false,
14+
}));
15+
} else {
16+
rollupConfig.output = {
17+
...rollupConfig.output,
18+
hoistTransitiveImports: false,
19+
};
20+
}
21+
922
return rollupConfig;
1023
};

packages/runtime/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module.exports = (rollupConfig, projectOptions) => {
2929
return 'polyfills';
3030
}
3131
},
32+
hoistTransitiveImports: false,
3233
}));
3334
} else {
3435
rollupConfig.output = {
@@ -38,6 +39,7 @@ module.exports = (rollupConfig, projectOptions) => {
3839
return 'polyfills';
3940
}
4041
},
42+
hoistTransitiveImports: false,
4143
};
4244
}
4345

packages/sdk/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = (rollupConfig, _projectOptions) => {
1717
return 'polyfills';
1818
}
1919
},
20+
hoistTransitiveImports: false,
2021
}));
2122
} else {
2223
rollupConfig.output = {
@@ -26,6 +27,7 @@ module.exports = (rollupConfig, _projectOptions) => {
2627
return 'polyfills';
2728
}
2829
},
30+
hoistTransitiveImports: false,
2931
};
3032
}
3133

packages/webpack-bundler-runtime/rollup.config.js

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,44 @@
11
const copy = require('rollup-plugin-copy');
22

3+
function manualChunks(id, projectOptions) {
4+
// if (id.includes(projectOptions.main)) {
5+
// return;
6+
// }
7+
// if (
8+
// projectOptions.additionalEntryPoints.some((entryPoint) => {
9+
// return id.includes(entryPoint);
10+
// })
11+
// ) {
12+
// return;
13+
// }
14+
if (id.includes('@swc/helpers')) {
15+
return 'polyfills';
16+
}
17+
// if (!id.includes('webpack-bundler-runtime')) {
18+
// return;
19+
// }
20+
// if (id.endsWith('types.ts')) {
21+
// return;
22+
// }
23+
// if (id.endsWith('.d.ts')) return;
24+
// const cName = id.split('src/')[1].replace('/', '_').replace('.ts', '');
25+
// return cName;
26+
}
27+
328
module.exports = (rollupConfig, projectOptions) => {
429
rollupConfig.external = [/@module-federation/];
30+
531
if (Array.isArray(rollupConfig.output)) {
632
rollupConfig.output = rollupConfig.output.map((c) => ({
733
...c,
8-
manualChunks: (id) => {
9-
debugger;
10-
if (id.includes('@swc/helpers')) {
11-
return 'polyfills';
12-
}
13-
},
34+
manualChunks: (id) => manualChunks(id, projectOptions),
35+
hoistTransitiveImports: false,
1436
}));
1537
} else {
1638
rollupConfig.output = {
1739
...rollupConfig.output,
18-
manualChunks: (id) => {
19-
debugger;
20-
if (id.includes('@swc/helpers')) {
21-
return 'polyfills';
22-
}
23-
},
40+
manualChunks: (id) => manualChunks(id, projectOptions),
41+
hoistTransitiveImports: false,
2442
};
2543
}
2644

packages/webpack-bundler-runtime/src/readme.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)