Skip to content

feat(css): extract CSS pipeline into @tsdown/css package#790

Merged
sxzz merged 2 commits intomainfrom
sxzz/css-split-test
Mar 4, 2026
Merged

feat(css): extract CSS pipeline into @tsdown/css package#790
sxzz merged 2 commits intomainfrom
sxzz/css-split-test

Conversation

@sxzz
Copy link
Member

@sxzz sxzz commented Mar 4, 2026

  • This PR contains AI-generated code, but I have carefully reviewed it myself. Otherwise, my PR may be closed.

Description

Split the CSS pipeline into two tiers for better modularity and optional advanced features:

  • Main package (tsdown): Provides basic CSS support via a built-in plugin that reads CSS files and emits them as assets. Shared utilities (createCssPostHooks, removePureCssChunks) are exported from tsdown/css.
  • @tsdown/css package: Advanced CSS features including Lightning CSS integration, preprocessor support (Sass/Less/Stylus), CSS syntax lowering via css.target, and css.minify.

Key changes:

  • Extract shared CSS post-processing hooks and pure CSS chunk handling into tsdown/css export path
  • Create @tsdown/css package with Lightning CSS bundleAsync/transform, preprocessor compilation, and target-based syntax lowering
  • Auto-detect @tsdown/css and use advanced plugin when installed, fall back to built-in basic plugin otherwise
  • Add css.minify and css.target options to CssOptions
  • Remove CSS source map code (aligning with Vite, which does not support CSS source maps in build mode)
  • Add comprehensive CSS tests (13 tests covering basic, unbundle, dts, splitting, minify, target, @import inlining, deep import chains, empty files)

Linked Issues

relate #472

Additional context

CSS source map support was intentionally omitted — Vite does not emit CSS source maps during build (see vitejs/vite#2830), so we align with that behavior.

@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit fc5a75a
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/69a7f10c2c13c300083aecbc
😎 Deploy Preview https://deploy-preview-790--tsdown-main.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 4, 2026

Open in StackBlitz

tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown@790 -D
npm i https://pkg.pr.new/rolldown/tsdown@790 -D
yarn add https://pkg.pr.new/rolldown/tsdown@790.tgz -D

create-tsdown

pnpm add https://pkg.pr.new/rolldown/tsdown/create-tsdown@790 -D
npm i https://pkg.pr.new/rolldown/tsdown/create-tsdown@790 -D
yarn add https://pkg.pr.new/rolldown/tsdown/create-tsdown@790.tgz -D

@tsdown/css

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@790 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/css@790 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/css@790.tgz -D

@tsdown/exe

pnpm add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@790 -D
npm i https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@790 -D
yarn add https://pkg.pr.new/rolldown/tsdown/@tsdown/exe@790.tgz -D

tsdown-migrate

pnpm add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@790 -D
npm i https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@790 -D
yarn add https://pkg.pr.new/rolldown/tsdown/tsdown-migrate@790.tgz -D

commit: 3c7e0bf

Split the CSS pipeline into two tiers:
- Main package (tsdown): basic CSS support with built-in plugin
- @tsdown/css: advanced CSS features (Lightning CSS, preprocessors, syntax lowering)

Key changes:
- Extract shared post-processing hooks (createCssPostHooks) and pure CSS chunk
  handling into tsdown/css export path
- Create @tsdown/css package with Lightning CSS integration, preprocessor support
  (Sass/Less/Stylus), and CSS syntax lowering via css.target option
- Auto-detect @tsdown/css and use advanced plugin when available
- Add css.minify and css.target options to CssOptions
- Remove CSS source map code (aligning with Vite which doesn't support CSS
  source maps in build mode)
- Add comprehensive CSS tests
@sxzz sxzz force-pushed the sxzz/css-split-test branch from d5cb7bd to fc5a75a Compare March 4, 2026 08:44
@sxzz
Copy link
Member Author

sxzz commented Mar 4, 2026

tsdown CSS vs Vite Lib Mode CSS Feature Comparison

(Reposting in English — please ignore the previous Chinese comment)

Implemented

Feature tsdown Vite Lib Mode Notes
CSS extraction/bundling css.fileName build.lib.cssFileName tsdown defaults to style.css
CSS Code Splitting css.splitting build.cssCodeSplit Both default to off in lib mode
CSS Minification css.minify build.cssMinify tsdown: Lightning CSS only; Vite: esbuild/lightningcss
CSS Syntax Lowering css.target build.cssTarget Both use esbuild target format
Preprocessors (Sass/Less/Stylus) css.preprocessorOptions css.preprocessorOptions Aligned, including additionalData
@import inlining Lightning CSS bundleAsync postcss-import / Lightning CSS Different implementation, same result
Lightning CSS passthrough css.lightningcss css.lightningcss Aligned
Pure CSS chunk removal Logic aligned with Vite

Missing Features

Feature Vite Config Priority Notes
CSS Modules css.modules High *.module.css support including localsConvention, generateScopedName, composes, etc. Commonly used in library development
PostCSS support css.postcss High Tailwind CSS, Autoprefixer, and the broader ecosystem rely on PostCSS. Vite supports both inline config and auto-discovery of config files
CSS url() asset resolution Built-in Medium Path rewriting for url() and image-set(). Lightning CSS handles some of this, but lacks a full asset pipeline
css.transformer selection css.transformer Low Vite supports 'postcss' | 'lightningcss' toggle. tsdown currently uses Lightning CSS only
Preprocessor worker pool css.preprocessorMaxWorkers Low Multi-threaded preprocessor compilation for large projects
CSS inline/URL queries ?inline / ?url Low import styles from './foo.css?inline' query parameter support
CSS Source Maps build.sourcemap Vite doesn't fully support CSS source maps in build mode either (vitejs/vite#2830). Intentionally skipped

Summary

Core CSS features (extraction, splitting, minification, syntax lowering, preprocessors, @import inlining) are aligned with Vite lib mode. The main missing high-priority features are CSS Modules and PostCSS support.

@sxzz sxzz mentioned this pull request Mar 4, 2026
14 tasks
@sxzz sxzz changed the title feat: extract CSS pipeline into @tsdown/css package feat(css): extract CSS pipeline into @tsdown/css package Mar 4, 2026
@sxzz sxzz merged commit e4cbeca into main Mar 4, 2026
15 checks passed
@sxzz sxzz deleted the sxzz/css-split-test branch March 4, 2026 08:56
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.

1 participant