Skip to content

Replace babel-loader with swc-loader for webpack transpilation#14595

Merged
rtibbles merged 2 commits into
learningequality:developfrom
rtibbles:swc-loader-transpilation
Apr 13, 2026
Merged

Replace babel-loader with swc-loader for webpack transpilation#14595
rtibbles merged 2 commits into
learningequality:developfrom
rtibbles:swc-loader-transpilation

Conversation

@rtibbles
Copy link
Copy Markdown
Member

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:

  • Core bundle entry point — SWC supports core-js entry expansion, but has known bugs in its polyfilling behavior that could cause regressions for our supported browsers. Babel's @babel/preset-env with useBuiltIns: 'entry' is more reliable here.
  • Jest transforms — SWC's Jest transpiler didn't work out of the box, and Babel is straightforward here. Config and dependencies are moved from kolibri-build to kolibri-jest-config.

References

Builds on the build time improvements in #14457.

Reviewer guidance

  • Run pnpm build and verify the production build completes without errors
  • Run pnpm test-jest to confirm Jest transforms still work with the moved Babel config
  • The SWC minifier options in packages/kolibri-build/src/webpack.config.base.js:117 are worth a close look — the compress/mangle/output options have slightly different semantics than Terser's
  • parallel: true was removed from TerserPlugin — it's ignored when using swcMinify since SWC's native code is already fast single-threaded

AI 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

npm Package Versions

Merging this PR will publish the following packages to npm:

Package Current New
kolibri-build 1.0.0 1.1.0

Warning

The following packages have changed files but no version bump:

Package Version Changed files
kolibri-jest-config 1.0.0 2

If these changes affect published code, consider bumping the version.

@rtibbles rtibbles force-pushed the swc-loader-transpilation branch from ab358ba to 0b6e406 Compare April 13, 2026 17:30
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

@rtibbles rtibbles marked this pull request as ready for review April 13, 2026 18:19
rtibbles and others added 2 commits April 13, 2026 12:55
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>
@rtibbles rtibbles force-pushed the swc-loader-transpilation branch from 0b6e406 to dc76737 Compare April 13, 2026 19:55
@bjester
Copy link
Copy Markdown
Member

bjester commented Apr 13, 2026

I ran pnpm run devserver-hot and make assets, then accessed Kolibri and noticed no issues. It's definitely faster, particularly the production build.

Although, I noticed a couple things possibly worth investigating:

  1. It doesn't seem to be necessarily an issue, but I noticed this error running make assets. I don't think it should be loading map files for dependencies? but also it's trying to append a URL to a path or something:
[INFO: Kolibri Build] Completed 'kolibri.plugins.policies.app' bundle in 7.168s!
  ERROR  failed to read input source map: failed to find input source map file "https://cdn.jsdelivr.net/gh/AnonyCo/FastestSmallestTextEncoderDecoder/EncoderDecoderTogether.min.js.map" in "/home/bjester/Projects/learningequality/kolibri/swc-loader-transpilation/node_modules/.pnpm/fastestsmallesttextencoderdecoder@1.0.22/node_modules/fastestsmallesttextencoderdecoder/EncoderDecoderTogether.min.js" file as either "/home/bjester/Projects/learningequality/kolibri/swc-loader-transpilation/node_modules/.pnpm/fastestsmallesttextencoderdecoder@1.0.22/node_modules/fastestsmallesttextencoderdecoder/https://cdn.jsdelivr.net/gh/AnonyCo/FastestSmallestTextEncoderDecoder/EncoderDecoderTogether.min.js.map" or with appended .map
    at crates/swc/src/lib.rs:400
  1. Also running make assets, I notice some messages for the mathjax files are not computing the size difference properly and outputting warnings:
[INFO: Kolibri Compressor] Successfully compressed: kolibri/plugins/perseus_viewer/static/mathjax/2.1/jax/output/HTML-CSS/fonts/TeX/WinIE6/Regular/AMS.js by -Infinity %
[WARN: Kolibri Compressor] Compressed size is more than 75% of original size
[INFO: Kolibri Compressor] Successfully compressed: kolibri/plugins/perseus_viewer/static/mathjax/2.1/jax/output/HTML-CSS/fonts/TeX/WinIE6/Regular/Bold.js by -Infinity %
[WARN: Kolibri Compressor] Compressed size is more than 75% of original size

@rtibbles
Copy link
Copy Markdown
Member Author

It doesn't seem to be necessarily an issue, but I noticed this error running make assets. I don't think it should be loading map files for dependencies? but also it's trying to append a URL to a path or something:

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.

Also running make assets, I notice some messages for the mathjax files are not computing the size difference properly and outputting warnings:

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.

I ran pnpm run devserver-hot and make assets, then accessed Kolibri and noticed no issues. It's definitely faster, particularly the production build.

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.

Copy link
Copy Markdown
Member

@bjester bjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cuts the production build time in half! My concerns have been acknowledged

@rtibbles rtibbles merged commit 07fbe39 into learningequality:develop Apr 13, 2026
62 of 63 checks passed
@rtibbles rtibbles deleted the swc-loader-transpilation branch April 13, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants