Repository navigation
perf(css): reuse Sass async compiler - #1001
Conversation
✅ Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tsdown
create-tsdown
@tsdown/css
@tsdown/exe
tsdown-migrate
commit: |
There was a problem hiding this comment.
Pull request overview
This PR improves SCSS/Sass preprocessing performance in @tsdown/css by reusing a persistent Sass AsyncCompiler (when supported by the loaded Sass implementation) instead of relying on the module-level compileStringAsync() that may spawn and dispose an embedded compiler per transform (notably in sass-embedded). It also ensures the compiler is disposed appropriately and adds targeted tests for the new behavior.
Changes:
- Add a small internal abstraction (
SassModule/SassCompiler) and implementloadSassCompiler()to reuse a singleton async compiler wheninitAsyncCompiler()is available. - Ensure the async compiler is disposed after non-watch builds and when the watcher closes.
- Add tests covering async compiler reuse/disposal and fallback to module-level compilation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/css/src/preprocessors.ts | Introduces async compiler reuse with loadSassCompiler() and cleanup via disposeSassCompiler(), and routes Sass compilation through the reusable compiler. |
| packages/css/src/preprocessors.test.ts | Adds focused Vitest coverage for compiler reuse, single-init behavior, disposal, and fallback. |
| packages/css/src/plugin.ts | Disposes the shared Sass compiler at appropriate lifecycle hooks (non-watch closeBundle, watch closeWatcher). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
Fixes #1000.
@tsdown/cssnow reuses a SassAsyncCompilerwhen the loaded Sass implementation exposesinitAsyncCompiler(). This avoids module-levelcompileStringAsync()spawning an embedded compiler for each SCSS transform. The compiler is disposed after non-watch builds and when the watcher closes, so watch rebuilds can keep reusing it between runs.This also adds focused tests for async compiler reuse and fallback to module-level Sass compilation.
Linked Issues
Fixes #1000
Additional context
Validated with:
pnpm formatpnpm lintpnpm typecheckpnpm test run