Skip to content

feat(css): add PostCSS support with css.transformer option#791

Merged
sxzz merged 5 commits intomainfrom
sxzz/postcss-support
Mar 4, 2026
Merged

feat(css): add PostCSS support with css.transformer option#791
sxzz merged 5 commits intomainfrom
sxzz/postcss-support

Conversation

@sxzz
Copy link
Member

@sxzz sxzz commented Mar 4, 2026

Summary

Add PostCSS support to tsdown's CSS pipeline with a css.transformer option that controls mutually exclusive processing paths, aligned with Vite's design.

Changes

css.transformer option

  • 'postcss' (default): @import resolved by postcss-import, PostCSS plugins applied, Lightning CSS used only for final syntax lowering/minification
  • 'lightningcss': @import resolved by Lightning CSS bundleAsync(), PostCSS not used at all

css.postcss option

  • Inline PostCSS config ({ plugins: [...] }) or config file path ('./config')
  • Auto-detects postcss.config.js from project root when omitted

@tsdown/css package (from #790)

  • Extract advanced CSS pipeline into separate @tsdown/css package
  • Preprocessors (Sass/Less/Stylus), Lightning CSS, PostCSS processing
  • Auto-detected and loaded when installed

File Changes

  • src/features/css/index.ts: Add transformer, postcss to CssOptions/ResolvedCssOptions
  • packages/css/src/index.ts: Refactor into loadWithLightningCSS / loadWithPostCSS paths
  • packages/css/src/postcss.ts: PostCSS processing with auto postcss-import injection
  • src/features/css/post.ts: Extract shared CSS post-processing hooks
  • src/features/css/pure-chunk.ts: Pure CSS chunk handling
  • src/css.ts: New tsdown/css export for shared types
  • docs/options/css.md, docs/zh-CN/options/css.md: Document transformer, PostCSS options
  • tests/css.test.ts: 18 tests covering both transformer paths

Type of Change

  • New feature
  • Documentation update

Testing

  • 18 CSS tests covering: basic, unbundle, dts, splitting, minify, syntax lowering, @import inlining, PostCSS plugins (inline + config file), PostCSS with @import, Lightning CSS transformer path, Lightning CSS ignoring PostCSS plugins
  • All tests passing

🤖 Generated with Claude Code

Add PostCSS processing to the `@tsdown/css` CSS pipeline. PostCSS runs
after preprocessors (Sass/Less/Stylus) and before Lightning CSS target
lowering/minification, aligned with Vite's approach.

- Add `css.postcss` option supporting inline config (object with plugins)
  or file-based config auto-detection via `postcss-load-config`
- Add `postcss` as optional peer dependency of `@tsdown/css`
- Add `postcss-load-config` as dependency for config file resolution
- Cache file-based PostCSS config per search path
- Track PostCSS plugin dependencies for watch mode
@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for tsdown-main ready!

Name Link
🔨 Latest commit 624e153
🔍 Latest deploy log https://app.netlify.com/projects/tsdown-main/deploys/69a8009b6bf70d0007b99ed6
😎 Deploy Preview https://deploy-preview-791--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@791 -D
npm i https://pkg.pr.new/rolldown/tsdown@791 -D
yarn add https://pkg.pr.new/rolldown/tsdown@791.tgz -D

create-tsdown

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

@tsdown/css

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

@tsdown/exe

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

tsdown-migrate

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

commit: 01e30ef

autofix-ci bot and others added 2 commits March 4, 2026 09:25
…ning CSS paths

- Add `css.transformer` option ('postcss' | 'lightningcss') defaulting to 'postcss'
- PostCSS path: @import via postcss-import, PostCSS plugins, Lightning CSS for final transform
- Lightning CSS path: bundleAsync for @import, no PostCSS
- Add `css.postcss` option for inline PostCSS config or config file path
- Add postcss-import as optional peer dependency
- Update docs (EN/ZH) and skills reference with transformer/postcss documentation
- Add tests for lightningcss transformer path
@sxzz sxzz changed the title feat(css): add PostCSS support feat(css): add PostCSS support with css.transformer option Mar 4, 2026
@sxzz sxzz merged commit 35bef69 into main Mar 4, 2026
15 checks passed
@sxzz sxzz deleted the sxzz/postcss-support branch March 4, 2026 09:54
@sxzz sxzz mentioned this pull request Mar 4, 2026
16 tasks
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