feat(css): add css.inject option to preserve CSS imports in JS output#808
Merged
feat(css): add css.inject option to preserve CSS imports in JS output#808
css.inject option to preserve CSS imports in JS output#808Conversation
When enabled, JS output retains `import './style.css'` statements pointing
to emitted CSS files so consumers automatically load the CSS.
- Add `css.inject` option to `CssOptions` (requires `@tsdown/css`)
- Support deprecated `injectStyle` top-level option for tsup migration
- Refactor `createCssPostHooks` into standalone `CssPostPlugin`
- Return `Plugin[]` from both `CssPlugin` functions
- Fix CSS asset hash resolution for async/split chunks
- Add migration transform: `injectStyle: true` → `css: { inject: true }`
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
✅ 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: |
Prepend a `;` to sourcemap mappings for each injected CSS import line, keeping the JS sourcemap accurate after code modification. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…nd sourcemap Instead of removing pure CSS chunk imports and prepending CSS imports (which reverses order and breaks sourcemap), swap the file extension in-place (.mjs/.cjs/.js → .css). This preserves both CSS cascade order and sourcemap line positions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add relaxed detection in removePureCssChunks for wrapper chunks (JS files that only import CSS) while preserving entry/dynamic entry chunks - Exclude isEntry and isDynamicEntry from pureCssChunks in inject plugin so dynamic entries get CSS imports prepended correctly - Add test for shared CSS-only chunk import rewriting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
css.injectoption that preservesimport './style.css'statements in JS output, so library consumers automatically load CSS alongside JSinjectStyletop-level option for seamless tsup migrationCssPostPlugin, with bothCssPluginfunctions returningPlugin[]!~{000}~)injectStyle: true→css: { inject: true }Test plan
injectStyle→css.injectAST transform🤖 Generated with Claude Code