Skip to content

Commit 6085552

Browse files
committed
Improve rollup perf
1 parent 833060e commit 6085552

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

packages/webamp/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/coverage
66
/examples/webpack/bundle.js
77
**/__diff_output__/
8+
.rollup.cache

packages/webamp/CHANGELOG.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
### Improvements
88

9-
- New `webamp/butterchurn` entry point which is a single bundle which includes the Butterchurn Milkdrop visualizer by default. This grows the module size by a few hundred kilobytes, but allows you to use Butterchurn without having to install it separately.
10-
- Switched id3/metadata parsing from using a very old version of `music-metadata-browser` to the latest version of `music-metadata`. `music-metadata-browser` is still supported for users of `webamp/lazy` for backwards compatibility, but it is no longer the default.
119
- Added new `Webamp` instance methods:
1210
- `webamp.toggleShuffle`
1311
- `webamp.toggleRepeat`
@@ -17,12 +15,9 @@
1715

1816
### Bug Fixes
1917

20-
- Fixed broken ID3 tag and bitrate parsing.
2118
- Fix bug where scrolling the main window or playlist window would change the volume but also (incorrectly) scroll the page.
2219
- Fix bug where resizing the window such that the current layout cannot fit on the page, while also scrolled down the page, would cause the layout to be recentered out of view.
2320
- Avoid a console log from Redux Dev Tools.
24-
- Don't show Milkdrop window option in context menu if Milkdrop is not enabled.
25-
- Fix bug on iPhone where Milkdrop window would resize incorrectly if you attempted to enter fullscreen mode, which is not supported on iPhones.
2621

2722
## 2.1.2 [CURRENT]
2823

packages/webamp/scripts/rollup.mjs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,28 @@ const BUNDLES = [
9191
build();
9292

9393
async function build() {
94-
for (const bundleDesc of BUNDLES) {
95-
console.log(`=======[ Building ${bundleDesc.name} ]=======`);
94+
console.log(`🚀 Building ${BUNDLES.length} bundles in parallel...`);
95+
96+
const buildPromises = BUNDLES.map(async (bundleDesc) => {
97+
console.log(`📦 Building ${bundleDesc.name}...`);
9698
const plugins = getPlugins({
9799
outputFile: bundleDesc.output.file,
98100
minify: bundleDesc.minify,
99101
});
100102
const bundle = await rollup({
101103
input: bundleDesc.input,
102104
plugins,
105+
// Enable tree shaking optimizations
106+
treeshake: {
107+
moduleSideEffects: false,
108+
propertyReadSideEffects: false,
109+
tryCatchDeoptimization: false,
110+
},
111+
// Optimize external dependencies handling
112+
external: (id) => {
113+
// Don't externalize these - we want them bundled for browser compatibility
114+
return false;
115+
},
103116
onwarn: (warning, warn) => {
104117
// Suppress expected circular dependency warnings from external libraries
105118
if (warning.code === "CIRCULAR_DEPENDENCY") {
@@ -123,5 +136,9 @@ async function build() {
123136
sourcemap: true,
124137
...bundleDesc.output,
125138
});
126-
}
139+
console.log(`✅ Completed ${bundleDesc.name}`);
140+
});
141+
142+
await Promise.all(buildPromises);
143+
console.log(`🎉 All ${BUNDLES.length} bundles built successfully!`);
127144
}

packages/webamp/scripts/rollupPlugins.mjs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export function getPlugins({ minify, outputFile, vite }) {
2222
vite ? null : stripInlineSuffix(),
2323
// https://rollupjs.org/troubleshooting/#warning-treating-module-as-external-dependency
2424
// TODO: We could offer a version which does not inline React/React-DOM
25-
nodeResolve(),
25+
nodeResolve({
26+
browser: true,
27+
preferBuiltins: false,
28+
// Skip deep resolution for better performance
29+
dedupe: ["react", "react-dom"],
30+
}),
2631
// Needed for music-metadata-browser in the Webamp bundle which depends upon
2732
// being able to use some polyfillable node APIs
2833
nodePolyfills(),
@@ -51,8 +56,32 @@ export function getPlugins({ minify, outputFile, vite }) {
5156
// because react-redux import react as if it were an es6 module, but it is not.
5257
commonjs(),
5358
// Must come after commonjs
54-
babel({ babelHelpers: "bundled", compact: minify }),
55-
minify ? terser() : null,
59+
babel({
60+
babelHelpers: "bundled",
61+
compact: minify,
62+
// Optimize Babel by excluding node_modules and only processing necessary files
63+
exclude: ["node_modules/**"],
64+
include: ["js/**/*"],
65+
}),
66+
minify
67+
? terser({
68+
compress: {
69+
// eslint-disable-next-line camelcase
70+
drop_console: true,
71+
// eslint-disable-next-line camelcase
72+
drop_debugger: true,
73+
// eslint-disable-next-line camelcase
74+
pure_funcs: ["console.log", "console.debug"],
75+
passes: 2,
76+
},
77+
mangle: {
78+
safari10: true,
79+
},
80+
format: {
81+
comments: false,
82+
},
83+
})
84+
: null,
5685
// Generate a report so we can see how our bundle size is spent
5786
visualizer({ filename: `./${outputFile}.html` }),
5887
].filter(Boolean);

0 commit comments

Comments
 (0)