Skip to content

CLUE-406 chore: replace ts-loader with swc-loader for ~3x faster builds - #2756

Draft
scytacki wants to merge 1 commit into
masterfrom
CLUE-406-swc-loader-faster-builds
Draft

CLUE-406 chore: replace ts-loader with swc-loader for ~3x faster builds#2756
scytacki wants to merge 1 commit into
masterfrom
CLUE-406-swc-loader-faster-builds

Conversation

@scytacki

@scytacki scytacki commented Feb 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace ts-loader with swc-loader (Rust-based transpiler) for ~3x faster dev builds
  • Add ForkTsCheckerWebpackPlugin to run TypeScript type checking in a parallel process
  • Configure ESLintPlugin with lintDirtyModulesOnly in dev mode
  • Retain ts-loader for CODE_COVERAGE builds (Istanbul instrumentation requires it)

Build performance improvement:

Metric Before After Improvement
Dev initial build ~31s ~10s 3x faster
Core file rebuild ~2.2s ~0.7s 3x faster

Test plan

  • Verify npm start works and HMR rebuilds are fast
  • Verify TypeScript errors still appear in the browser overlay
  • Verify ESLint errors still appear in the browser overlay
  • Verify CODE_COVERAGE=true npm start still works (uses ts-loader)
  • Verify npm run build succeeds
  • Verify npm test passes

🤖 Generated with Claude Code

- Use swc-loader (Rust-based) for transpilation instead of ts-loader
- Add ForkTsCheckerWebpackPlugin for parallel type checking
- Configure ESLintPlugin with lintDirtyModulesOnly in dev mode
- Retain ts-loader for CODE_COVERAGE builds (Istanbul instrumentation)
- Add build performance documentation and benchmark script

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Feb 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.75%. Comparing base (2aaec63) to head (2113d5e).

❗ There is a different number of reports uploaded between BASE (2aaec63) and HEAD (2113d5e). Click for more details.

HEAD has 24 uploads less than BASE
Flag BASE (2aaec63) HEAD (2113d5e)
jest 2 1
cypress-smoke 2 1
cypress-regression 15 0
cypress 7 0
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2756       +/-   ##
===========================================
- Coverage   86.81%   66.75%   -20.06%     
===========================================
  Files         829      824        -5     
  Lines       44549    44526       -23     
  Branches    11462    11460        -2     
===========================================
- Hits        38673    29723     -8950     
- Misses       5527    13767     +8240     
- Partials      349     1036      +687     
Flag Coverage Δ
cypress ?
cypress-regression ?
cypress-smoke 43.89% <ø> (-0.27%) ⬇️
jest 49.85% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cypress

cypress Bot commented Feb 6, 2026

Copy link
Copy Markdown

collaborative-learning    Run #17660

Run Properties:  status check passed Passed #17660  •  git commit 2113d5e0e3: CLUE-406 chore: replace ts-loader with swc-loader for ~3x faster builds
Project collaborative-learning
Branch Review CLUE-406-swc-loader-faster-builds
Run status status check passed Passed #17660
Run duration 02m 58s
Commit git commit 2113d5e0e3: CLUE-406 chore: replace ts-loader with swc-loader for ~3x faster builds
Committer Scott Cytacki
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
View all changes introduced in this branch ↗︎

@kswenson

kswenson commented Aug 6, 2026

Copy link
Copy Markdown
Member

Heads up before this merges: it reproduces a bug we just fixed in CODAP v3, in
concord-consortium/codap#2672.

The problem: swc-loader does not read tsconfig.json. With no jsc.target in the loader
options, swc falls back to its ES5 default — down-leveling constvar, expanding optional
chaining, nullish coalescing, arrow functions, class, generators, etc. CLUE's
tsconfig.json sets "target": "ES2015", so ts-loader emits ES2015 today; swapping in
swc-loader as written here silently drops the app bundle to ES5. That's transpiler bloat
downloaded by 100% of users, and it doesn't show up as a build error or a test failure — the
diff looks fine and the app still runs.

For scale: in CODAP, going from swc's ES5 default to es2020 cut the app chunk by
674 KB raw / 98 KB gzip (−8.3% / −4.5% of total JS) with no change in build time. CLUE's
src is comparable in size, so expect the same order of magnitude. Only the app chunks are
affected — swc only processes src, so vendor chunks are unchanged.

Suggested fix: set jsc.target, and derive it from tsconfig.json rather than hardcoding a
second value that's free to drift the next time tsconfig.json changes. What CODAP does
(see the diff in that PR):

  • read the target through the TypeScript compiler API — ts.readConfigFile(...) rather than
    require(), because tsconfig.json has comments in it and require() would throw;
  • throw on a missing or unrecognized target instead of falling back, since a silent
    fallback lands right back on ES5 — the exact bug being fixed, and one that is invisible in a
    diff.

A couple of CLUE-specific notes:

  • The derived value here would be es2015, which just restores parity with what ts-loader
    emits today. Whether to raise tsconfig.json to es2020 is a separate call — worth making,
    but it changes tsc/ts-jest output too, so probably its own story. (There's a
    browserslist in package.json"> 0.2%, last 5 versions, Firefox ESR, not dead" — but
    nothing wires it to swc, and not dead is a much lower floor than ES2020.)
  • CODAP also had to add tsconfig.json to cache.buildDependencies so that changing the target
    invalidates webpack's persistent cache. CLUE has no filesystem cache in webpack.config.js
    today, so that's not needed now — just something to remember if one gets added.
  • The CODE_COVERAGE branch keeps ts-loader, and Jest goes through ts-jest, which reads
    tsconfig.json. Both are unaffected either way.

How to verify: run a production build and grep the app chunk for ??, ?., =>, class,
and const. If they've all been rewritten into helpers and var, the target isn't taking
effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants