Replace babel-loader with swc-loader for webpack transpilation#14595
Conversation
npm Package VersionsMerging this PR will publish the following packages to npm:
Warning The following packages have changed files but no version bump:
If these changes affect published code, consider bumping the version. |
ab358ba to
0b6e406
Compare
Build Artifacts
Smoke test screenshot |
SWC is a Rust-based compiler that is significantly faster than Babel for syntax transforms. This cuts the webpack production build time roughly in half. Babel-loader is retained only in the core bundle's buildConfig to expand the core-js polyfill entry import via @babel/preset-env. Babel configuration for Jest is moved from kolibri-build to kolibri-jest-config, and the root babel.config.js is removed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
TerserPlugin supports SWC as an alternative minification backend. Since @swc/core is already available for transpilation, this avoids the overhead of Terser's JS-based minifier. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
0b6e406 to
dc76737
Compare
|
I ran Although, I noticed a couple things possibly worth investigating:
|
Yes - when the source map for the file is hosted on a CDN it doesn't seem to work properly - this was being silently dropped by babel previously, and I couldn't work out how to suppress the warning here.
Interesting - I think I can look at this further within the scope of #14388 where these files are dropped in favour of a newer version of Mathjax.
Noting that because we dropped babel transpilation from the dev build - this will make no difference there! But yes, on the production build it should be a noticeable speedup. |
bjester
left a comment
There was a problem hiding this comment.
Cuts the production build time in half! My concerns have been acknowledged
Summary
Replace babel-loader with swc-loader for webpack transpilation and switch TerserPlugin to use SWC's minifier. SWC is a Rust-based compiler that roughly halves the production build time.
Babel is retained in two places:
@babel/preset-envwithuseBuiltIns: 'entry'is more reliable here.kolibri-buildtokolibri-jest-config.References
Builds on the build time improvements in #14457.
Reviewer guidance
pnpm buildand verify the production build completes without errorspnpm test-jestto confirm Jest transforms still work with the moved Babel configpackages/kolibri-build/src/webpack.config.base.js:117are worth a close look — thecompress/mangle/outputoptions have slightly different semantics than Terser'sparallel: truewas removed from TerserPlugin — it's ignored when usingswcMinifysince SWC's native code is already fast single-threadedAI usage
Claude Code was used to implement the SWC migration, with manual review of the generated config changes and verification that builds and tests pass.