You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/options/css.md
+15-33Lines changed: 15 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,22 +5,19 @@ CSS support in `tsdown` is still an experimental feature. While it covers the co
5
5
> [!WARNING] Experimental Feature
6
6
> CSS support is experimental. Please test thoroughly and report any issues you encounter. The API and behavior may change as the feature matures.
7
7
8
-
## Basic vs Advanced CSS
8
+
## Getting Started
9
9
10
-
`tsdown` provides two levels of CSS support:
11
-
12
-
-**Built-in (basic):** CSS file extraction and bundling works out of the box — no extra dependencies needed.
13
-
-**Advanced (`@tsdown/css`):** Preprocessors (Sass/Less/Stylus), CSS syntax lowering, minification, and `@import` inlining require the `@tsdown/css` package:
10
+
All CSS support in `tsdown` is provided by the `@tsdown/css` package. Install it to enable CSS handling:
14
11
15
12
```bash
16
13
npm install -D @tsdown/css
17
14
```
18
15
19
-
When `@tsdown/css` is installed, the advanced CSS plugin is automatically used in place of the built-in one.
16
+
When `@tsdown/css` is installed, CSS processing is automatically enabled.
20
17
21
18
## CSS Import
22
19
23
-
Importing `.css` files from your TypeScript or JavaScript entry points is supported out of the box. The CSS content is extracted and emitted as a separate `.css` asset file:
20
+
Importing `.css` files from your TypeScript or JavaScript entry points is supported. The CSS content is extracted and emitted as a separate `.css` asset file:
24
21
25
22
```ts
26
23
// src/index.ts
@@ -35,7 +32,7 @@ This produces both `index.mjs` and `index.css` in the output directory.
35
32
36
33
### `@import` Inlining
37
34
38
-
When `@tsdown/css` is installed, CSS `@import` statements are automatically resolved and inlined into the output. This means you can use `@import` to organize your CSS across multiple files without producing separate output files:
35
+
CSS `@import` statements are automatically resolved and inlined into the output. This means you can use `@import` to organize your CSS across multiple files without producing separate output files:
39
36
40
37
```css
41
38
/* style.css */
@@ -51,9 +48,6 @@ All imported CSS is bundled into a single output file with `@import` statements
51
48
52
49
## CSS Pre-processors
53
50
54
-
> [!NOTE]
55
-
> Requires `@tsdown/css` to be installed.
56
-
57
51
`tsdown` provides built-in support for `.scss`, `.sass`, `.less`, `.styl`, and `.stylus` files. The corresponding pre-processor must be installed as a dev dependency:
58
52
59
53
::: code-group
@@ -138,9 +132,6 @@ export default defineConfig({
138
132
139
133
## CSS Minification
140
134
141
-
> [!NOTE]
142
-
> Requires `@tsdown/css` to be installed.
143
-
144
135
Enable CSS minification via `css.minify`:
145
136
146
137
```ts
@@ -155,9 +146,6 @@ Minification is powered by [Lightning CSS](https://lightningcss.dev/).
155
146
156
147
## CSS Target
157
148
158
-
> [!NOTE]
159
-
> Requires `@tsdown/css` to be installed.
160
-
161
149
By default, CSS syntax lowering uses the top-level [`target`](/options/target) option. You can override this specifically for CSS with `css.target`:
162
150
163
151
```ts
@@ -182,9 +170,6 @@ export default defineConfig({
182
170
183
171
## CSS Transformer
184
172
185
-
> [!NOTE]
186
-
> Requires `@tsdown/css` to be installed.
187
-
188
173
The `css.transformer` option controls how CSS is processed. PostCSS and Lightning CSS are **mutually exclusive** processing paths:
189
174
190
175
-**`'lightningcss'`** (default): `@import` is resolved by Lightning CSS's `bundleAsync()`, and PostCSS is **not used at all**.
@@ -234,9 +219,6 @@ When `css.postcss` is omitted and `transformer` is `'postcss'`, tsdown auto-dete
234
219
235
220
## Lightning CSS
236
221
237
-
> [!NOTE]
238
-
> Requires `@tsdown/css` to be installed.
239
-
240
222
`tsdown` uses [Lightning CSS](https://lightningcss.dev/) for CSS syntax lowering — transforming modern CSS features into syntax compatible with older browsers based on your `target` setting.
241
223
242
224
To enable CSS syntax lowering, install `lightningcss`:
0 commit comments