@visulima/rollup-plugin-css 1.0.0-alpha.1 → 1.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +96 -0
- package/LICENSE.md +83 -79
- package/README.md +349 -109
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -0
- package/dist/loaders/less/index.d.ts +17 -9
- package/dist/loaders/less/index.js +1 -0
- package/dist/loaders/lightningcss.d.ts +2 -2
- package/dist/loaders/lightningcss.js +3 -0
- package/dist/loaders/postcss/index.d.ts +2 -2
- package/dist/loaders/postcss/{index.mjs → index.js} +1 -1
- package/dist/loaders/sass/index.d.ts +18 -9
- package/dist/loaders/sass/{index.mjs → index.js} +1 -1
- package/dist/loaders/sourcemap.d.ts +2 -2
- package/dist/loaders/sourcemap.js +1 -0
- package/dist/loaders/stylus/index.d.ts +17 -9
- package/dist/loaders/stylus/index.js +1 -0
- package/dist/loaders/tailwindcss-oxide.d.ts +2 -2
- package/dist/loaders/tailwindcss-oxide.js +1 -0
- package/dist/minifiers/cssnano.d.ts +2 -2
- package/dist/minifiers/lightningcss.d.ts +2 -2
- package/dist/packem_shared/concat-BnU-BO62.js +3 -0
- package/dist/packem_shared/{cssModulesTypesPlugin-B9_bJo_B.mjs → cssModulesTypesPlugin-CjGroK2y.js} +1 -1
- package/dist/packem_shared/generate-js-exports-BhS4eLrN.js +23 -0
- package/dist/packem_shared/getMap-CxaNZNeI.js +1 -0
- package/dist/packem_shared/inferModeOption-9h3Eq6JH.js +1 -0
- package/dist/packem_shared/loadModule-D20jQQNu.js +1 -0
- package/dist/packem_shared/resolve-anj9ucIq.js +1 -0
- package/dist/packem_shared/rollupCssPlugin-CChaHsU3.js +3 -0
- package/dist/packem_shared/{types-BS4hXME3.d.mts → types-D3VQL1eC.d.ts} +7 -3
- package/dist/utils/index.d.ts +4 -2
- package/dist/utils/index.js +1 -0
- package/package.json +56 -41
- package/dist/index.d.mts +0 -20
- package/dist/index.mjs +0 -1
- package/dist/loaders/less/index.d.mts +0 -17
- package/dist/loaders/less/index.mjs +0 -1
- package/dist/loaders/lightningcss.d.mts +0 -17
- package/dist/loaders/lightningcss.mjs +0 -3
- package/dist/loaders/postcss/index.d.mts +0 -17
- package/dist/loaders/sass/index.d.mts +0 -18
- package/dist/loaders/sourcemap.d.mts +0 -17
- package/dist/loaders/sourcemap.mjs +0 -1
- package/dist/loaders/stylus/index.d.mts +0 -17
- package/dist/loaders/stylus/index.mjs +0 -1
- package/dist/loaders/tailwindcss-oxide.d.mts +0 -17
- package/dist/loaders/tailwindcss-oxide.mjs +0 -1
- package/dist/minifiers/cssnano.d.mts +0 -17
- package/dist/minifiers/lightningcss.d.mts +0 -17
- package/dist/packem_shared/concat-BbvpVPBg.mjs +0 -3
- package/dist/packem_shared/generate-js-exports-Cg7EXFF1.mjs +0 -14
- package/dist/packem_shared/getMap-BL5hKEnR.mjs +0 -1
- package/dist/packem_shared/inferModeOption-DYyLMRb2.mjs +0 -1
- package/dist/packem_shared/loadModule-CovDETwT.mjs +0 -1
- package/dist/packem_shared/resolve-nqhcPNJ9.mjs +0 -1
- package/dist/packem_shared/rollupCssPlugin-D-7azn92.mjs +0 -3
- package/dist/packem_shared/types-BS4hXME3.d.ts +0 -185
- package/dist/utils/index.d.mts +0 -71
- package/dist/utils/index.mjs +0 -1
- /package/dist/minifiers/{cssnano.mjs → cssnano.js} +0 -0
- /package/dist/minifiers/{lightningcss.mjs → lightningcss.js} +0 -0
- /package/dist/packem_shared/{arrayFmt-Dek5cB7m.mjs → arrayFmt-Dek5cB7m.js} +0 -0
- /package/dist/packem_shared/{ensure-auto-modules-BU3xWEjl.mjs → ensure-auto-modules-BU3xWEjl.js} +0 -0
- /package/dist/packem_shared/{hasModuleSpecifier-DIZeev_W.mjs → hasModuleSpecifier-DIZeev_W.js} +0 -0
- /package/dist/packem_shared/{safeId-BN5akJYJ.mjs → safeId-BN5akJYJ.js} +0 -0
- /package/dist/packem_shared/{sourcemap-DGfgaUBb.mjs → sourcemap-DGfgaUBb.js} +0 -0
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ A comprehensive CSS processing plugin for [Packem](https://github.com/visulima/p
|
|
|
7
7
|
### 🎨 CSS Preprocessors
|
|
8
8
|
|
|
9
9
|
- **PostCSS** - Modern CSS transformations with plugin ecosystem
|
|
10
|
-
- **Sass/SCSS** - Popular CSS extension language
|
|
10
|
+
- **Sass/SCSS** - Popular CSS extension language
|
|
11
11
|
- **Less** - Dynamic stylesheet language
|
|
12
12
|
- **Stylus** - Expressive, dynamic, robust CSS
|
|
13
13
|
- **Tailwind CSS v4** - Latest Tailwind CSS with PostCSS integration
|
|
@@ -22,9 +22,10 @@ A comprehensive CSS processing plugin for [Packem](https://github.com/visulima/p
|
|
|
22
22
|
|
|
23
23
|
### 📦 Integration Modes
|
|
24
24
|
|
|
25
|
-
- **Inject** - Embed CSS in JavaScript and inject at runtime
|
|
25
|
+
- **Inject** - Embed CSS in JavaScript and inject at runtime (with customizable package and method)
|
|
26
26
|
- **Extract** - Extract CSS to separate `.css` files
|
|
27
27
|
- **Emit** - Pass processed CSS through the build pipeline
|
|
28
|
+
- **Inline** - Embed CSS as strings in JavaScript modules
|
|
28
29
|
|
|
29
30
|
### 🔤 TypeScript Support
|
|
30
31
|
|
|
@@ -91,21 +92,21 @@ The `@visulima/rollup-plugin-css` provides comprehensive CSS processing capabili
|
|
|
91
92
|
import { rollupCssPlugin } from "@visulima/rollup-plugin-css";
|
|
92
93
|
|
|
93
94
|
export default {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
plugins: [
|
|
96
|
+
rollupCssPlugin({
|
|
97
|
+
// Extract CSS to separate files
|
|
98
|
+
mode: "extract",
|
|
99
|
+
|
|
100
|
+
// Enable CSS modules for .module.css files
|
|
101
|
+
autoModules: /\.module\./,
|
|
102
|
+
|
|
103
|
+
// Enable source maps
|
|
104
|
+
sourceMap: true,
|
|
105
|
+
|
|
106
|
+
// CSS minification
|
|
107
|
+
minifier: "cssnano",
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
109
110
|
};
|
|
110
111
|
```
|
|
111
112
|
|
|
@@ -115,36 +116,33 @@ export default {
|
|
|
115
116
|
import { rollupCssPlugin } from "@visulima/rollup-plugin-css";
|
|
116
117
|
|
|
117
118
|
export default {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
minifier: "lightningcss",
|
|
146
|
-
})
|
|
147
|
-
]
|
|
119
|
+
plugins: [
|
|
120
|
+
rollupCssPlugin({
|
|
121
|
+
// File extensions to process
|
|
122
|
+
extensions: [".css", ".scss", ".sass", ".less", ".styl"],
|
|
123
|
+
|
|
124
|
+
// CSS Modules configuration
|
|
125
|
+
autoModules: true,
|
|
126
|
+
namedExports: true,
|
|
127
|
+
|
|
128
|
+
// PostCSS configuration
|
|
129
|
+
postcss: {
|
|
130
|
+
plugins: [require("autoprefixer"), require("tailwindcss")],
|
|
131
|
+
modules: {
|
|
132
|
+
generateScopedName: "[name]__[local]___[hash:base64:5]",
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
// Sass configuration
|
|
137
|
+
sass: {
|
|
138
|
+
includePaths: ["node_modules"],
|
|
139
|
+
outputStyle: "compressed",
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// Minification
|
|
143
|
+
minifier: "lightningcss",
|
|
144
|
+
}),
|
|
145
|
+
],
|
|
148
146
|
};
|
|
149
147
|
```
|
|
150
148
|
|
|
@@ -156,55 +154,80 @@ export default {
|
|
|
156
154
|
import { rollupCssPlugin } from "@visulima/rollup-plugin-css";
|
|
157
155
|
|
|
158
156
|
export default {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
plugins: [
|
|
158
|
+
rollupCssPlugin({
|
|
159
|
+
// Inject CSS into JavaScript
|
|
160
|
+
mode: "inject",
|
|
161
|
+
|
|
162
|
+
// Enable CSS modules
|
|
163
|
+
autoModules: true,
|
|
164
|
+
|
|
165
|
+
// PostCSS with autoprefixer
|
|
166
|
+
postcss: {
|
|
167
|
+
plugins: [require("autoprefixer")],
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
// Minification
|
|
171
|
+
minifier: "cssnano",
|
|
172
|
+
}),
|
|
173
|
+
],
|
|
176
174
|
};
|
|
177
175
|
```
|
|
178
176
|
|
|
177
|
+
#### Custom Injection Package and Method
|
|
178
|
+
|
|
179
|
+
You can customize the CSS injection by specifying a custom package and method:
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
rollupCssPlugin({
|
|
183
|
+
mode: [
|
|
184
|
+
"inject",
|
|
185
|
+
{
|
|
186
|
+
// Use your own CSS injection library
|
|
187
|
+
package: "my-custom-injector",
|
|
188
|
+
method: "injectCSS",
|
|
189
|
+
|
|
190
|
+
// Other inject options...
|
|
191
|
+
container: "body",
|
|
192
|
+
prepend: true,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
autoModules: true,
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
This allows you to:
|
|
200
|
+
|
|
201
|
+
- Use alternative CSS injection libraries
|
|
202
|
+
- Implement custom injection logic
|
|
203
|
+
- Override the default `@visulima/css-style-inject` behavior
|
|
204
|
+
|
|
179
205
|
### Tailwind CSS v4 with PostCSS
|
|
180
206
|
|
|
181
207
|
```typescript
|
|
182
208
|
import { rollupCssPlugin } from "@visulima/rollup-plugin-css";
|
|
183
209
|
|
|
184
210
|
export default {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
minifier: "cssnano",
|
|
196
|
-
})
|
|
197
|
-
]
|
|
211
|
+
plugins: [
|
|
212
|
+
rollupCssPlugin({
|
|
213
|
+
mode: "extract",
|
|
214
|
+
autoModules: true,
|
|
215
|
+
postcss: {
|
|
216
|
+
plugins: [require("@tailwindcss/postcss"), require("autoprefixer")],
|
|
217
|
+
},
|
|
218
|
+
minifier: "cssnano",
|
|
219
|
+
}),
|
|
220
|
+
],
|
|
198
221
|
};
|
|
199
222
|
```
|
|
200
223
|
|
|
201
224
|
```javascript
|
|
202
225
|
// postcss.config.js
|
|
203
226
|
export default {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
227
|
+
plugins: {
|
|
228
|
+
"@tailwindcss/postcss": {},
|
|
229
|
+
},
|
|
230
|
+
};
|
|
208
231
|
```
|
|
209
232
|
|
|
210
233
|
### Tailwind Oxide (Rust-based)
|
|
@@ -213,21 +236,77 @@ export default {
|
|
|
213
236
|
import { rollupCssPlugin } from "@visulima/rollup-plugin-css";
|
|
214
237
|
|
|
215
238
|
export default {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
239
|
+
plugins: [
|
|
240
|
+
rollupCssPlugin({
|
|
241
|
+
mode: "extract",
|
|
242
|
+
autoModules: true,
|
|
243
|
+
// Tailwind Oxide configuration
|
|
244
|
+
tailwind: {
|
|
245
|
+
oxide: true,
|
|
246
|
+
config: "./tailwind.config.js",
|
|
247
|
+
},
|
|
248
|
+
minifier: "cssnano",
|
|
249
|
+
}),
|
|
250
|
+
],
|
|
228
251
|
};
|
|
229
252
|
```
|
|
230
253
|
|
|
254
|
+
### Inline Mode
|
|
255
|
+
|
|
256
|
+
Embed CSS directly as strings in JavaScript modules. This reduces HTTP requests but increases bundle size. Ideal for small CSS files or critical CSS that needs to be available immediately.
|
|
257
|
+
|
|
258
|
+
```typescript
|
|
259
|
+
import { rollupCssPlugin } from "@visulima/rollup-plugin-css";
|
|
260
|
+
|
|
261
|
+
export default {
|
|
262
|
+
plugins: [
|
|
263
|
+
rollupCssPlugin({
|
|
264
|
+
mode: "inline",
|
|
265
|
+
autoModules: true,
|
|
266
|
+
namedExports: true,
|
|
267
|
+
minifier: "cssnano",
|
|
268
|
+
}),
|
|
269
|
+
],
|
|
270
|
+
};
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Benefits:**
|
|
274
|
+
|
|
275
|
+
- **Zero HTTP requests** - CSS is embedded directly in JavaScript
|
|
276
|
+
- **No race conditions** - CSS is available immediately when JavaScript executes
|
|
277
|
+
- **Smaller initial bundle** - No separate CSS file to load
|
|
278
|
+
- **Better caching** - CSS is cached with JavaScript bundle
|
|
279
|
+
|
|
280
|
+
**Trade-offs:**
|
|
281
|
+
|
|
282
|
+
- **Increased bundle size** - CSS content is included in JavaScript
|
|
283
|
+
- **No separate caching** - CSS can't be cached independently
|
|
284
|
+
- **Larger JavaScript** - Affects JavaScript parsing and execution time
|
|
285
|
+
|
|
286
|
+
**Use cases:**
|
|
287
|
+
|
|
288
|
+
- Critical CSS that must be available immediately
|
|
289
|
+
- Small CSS files where the overhead of a separate request isn't worth it
|
|
290
|
+
- Applications where CSS is dynamically generated or modified at runtime
|
|
291
|
+
- Components that need their CSS to be self-contained
|
|
292
|
+
|
|
293
|
+
```css
|
|
294
|
+
/* Input: styles.css */
|
|
295
|
+
.button {
|
|
296
|
+
background: blue;
|
|
297
|
+
color: white;
|
|
298
|
+
padding: 10px 20px;
|
|
299
|
+
}
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
// Output: JavaScript module with embedded CSS
|
|
304
|
+
var css = ".button{background:blue;color:white;padding:10px 20px;}";
|
|
305
|
+
|
|
306
|
+
export { css };
|
|
307
|
+
export default css;
|
|
308
|
+
```
|
|
309
|
+
|
|
231
310
|
## Examples
|
|
232
311
|
|
|
233
312
|
### CSS Modules with React
|
|
@@ -273,19 +352,15 @@ declare const test: "index_test_bcd2d774";
|
|
|
273
352
|
declare const container: "index_container_bcd2d774";
|
|
274
353
|
|
|
275
354
|
interface ModulesExports {
|
|
276
|
-
|
|
277
|
-
|
|
355
|
+
test: string;
|
|
356
|
+
container: string;
|
|
278
357
|
}
|
|
279
358
|
|
|
280
359
|
declare const modules_c21c94f2: ModulesExports;
|
|
281
360
|
|
|
282
361
|
export default modules_c21c94f2;
|
|
283
362
|
|
|
284
|
-
export {
|
|
285
|
-
css,
|
|
286
|
-
test,
|
|
287
|
-
container
|
|
288
|
-
};
|
|
363
|
+
export { css, test, container };
|
|
289
364
|
```
|
|
290
365
|
|
|
291
366
|
### Multiple CSS Preprocessors
|
|
@@ -386,9 +461,32 @@ rollupCssPlugin({
|
|
|
386
461
|
mode: "extract", // Creates separate CSS files
|
|
387
462
|
autoModules: true,
|
|
388
463
|
minifier: "cssnano",
|
|
389
|
-
})
|
|
464
|
+
});
|
|
390
465
|
```
|
|
391
466
|
|
|
467
|
+
**Benefits:**
|
|
468
|
+
|
|
469
|
+
- **Separate caching** - CSS can be cached independently from JavaScript
|
|
470
|
+
- **Parallel loading** - CSS and JavaScript can load simultaneously
|
|
471
|
+
- **Better performance** - Smaller JavaScript bundles, faster parsing
|
|
472
|
+
- **CDN optimization** - CSS can be served from CDN with different cache strategies
|
|
473
|
+
- **Selective loading** - Only load CSS for specific routes or components
|
|
474
|
+
|
|
475
|
+
**Trade-offs:**
|
|
476
|
+
|
|
477
|
+
- **Additional HTTP requests** - Separate CSS file must be fetched
|
|
478
|
+
- **Potential FOUC** - Flash of unstyled content if CSS loads after HTML
|
|
479
|
+
- **Build complexity** - Requires additional build step for CSS extraction
|
|
480
|
+
- **Dependency management** - Need to ensure CSS is loaded before JavaScript execution
|
|
481
|
+
|
|
482
|
+
**Use cases:**
|
|
483
|
+
|
|
484
|
+
- Large CSS files where separate caching is beneficial
|
|
485
|
+
- Applications with multiple CSS themes or variants
|
|
486
|
+
- Production builds where performance optimization is critical
|
|
487
|
+
- CDN-based deployments requiring separate asset optimization
|
|
488
|
+
- Applications where CSS needs to be loaded conditionally
|
|
489
|
+
|
|
392
490
|
### Inject Mode
|
|
393
491
|
|
|
394
492
|
Injects CSS directly into JavaScript at runtime. **Requires `@visulima/css-style-inject`:**
|
|
@@ -398,25 +496,164 @@ rollupCssPlugin({
|
|
|
398
496
|
mode: "inject", // CSS embedded in JS
|
|
399
497
|
autoModules: true,
|
|
400
498
|
minifier: "cssnano",
|
|
401
|
-
})
|
|
499
|
+
});
|
|
402
500
|
```
|
|
403
501
|
|
|
502
|
+
**Benefits:**
|
|
503
|
+
|
|
504
|
+
- **No separate HTTP requests** - CSS is bundled with JavaScript
|
|
505
|
+
- **Guaranteed availability** - CSS is always available when JavaScript executes
|
|
506
|
+
- **Simplified deployment** - Single JavaScript bundle to manage
|
|
507
|
+
- **Dynamic injection** - CSS can be injected conditionally or on-demand
|
|
508
|
+
- **Runtime control** - Full control over when and how CSS is applied
|
|
509
|
+
|
|
510
|
+
**Trade-offs:**
|
|
511
|
+
|
|
512
|
+
- **Larger JavaScript bundles** - CSS content increases JavaScript file size
|
|
513
|
+
- **Slower initial parsing** - JavaScript engine must process CSS content
|
|
514
|
+
- **No separate caching** - CSS can't be cached independently from JavaScript
|
|
515
|
+
- **Memory usage** - CSS content remains in JavaScript memory
|
|
516
|
+
|
|
517
|
+
**Use cases:**
|
|
518
|
+
|
|
519
|
+
- Single-page applications (SPAs) where CSS is always needed
|
|
520
|
+
- Applications requiring dynamic CSS injection
|
|
521
|
+
- Development builds where simplicity is preferred
|
|
522
|
+
- Applications with complex CSS loading logic
|
|
523
|
+
- Components that need guaranteed CSS availability
|
|
524
|
+
|
|
525
|
+
#### Advanced Inject Configuration
|
|
526
|
+
|
|
527
|
+
You can customize the injection behavior by passing an object to the `mode` option:
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
rollupCssPlugin({
|
|
531
|
+
mode: [
|
|
532
|
+
"inject",
|
|
533
|
+
{
|
|
534
|
+
// Custom package to import the injector from
|
|
535
|
+
package: "my-custom-css-injector",
|
|
536
|
+
|
|
537
|
+
// Custom method name to import
|
|
538
|
+
method: "injectStyles",
|
|
539
|
+
|
|
540
|
+
// Container for style injection (default: "head")
|
|
541
|
+
container: "body",
|
|
542
|
+
|
|
543
|
+
// Insert styles at the beginning of container
|
|
544
|
+
prepend: true,
|
|
545
|
+
|
|
546
|
+
// Use single style tag
|
|
547
|
+
singleTag: true,
|
|
548
|
+
|
|
549
|
+
// Custom attributes for style tag
|
|
550
|
+
attributes: { "data-theme": "dark" },
|
|
551
|
+
|
|
552
|
+
// Make injector treeshakeable
|
|
553
|
+
treeshakeable: true,
|
|
554
|
+
},
|
|
555
|
+
],
|
|
556
|
+
autoModules: true,
|
|
557
|
+
minifier: "cssnano",
|
|
558
|
+
});
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
**Custom Package and Method:**
|
|
562
|
+
|
|
563
|
+
- **`package`**: Override the default `@visulima/css-style-inject` package
|
|
564
|
+
- **`method`**: Override the default `cssStyleInject` method name
|
|
565
|
+
- **Use case**: When you want to use your own CSS injection library or have custom injection logic
|
|
566
|
+
|
|
567
|
+
### Inline Mode
|
|
568
|
+
|
|
569
|
+
Embeds CSS directly as strings in JavaScript modules:
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
rollupCssPlugin({
|
|
573
|
+
mode: "inline", // CSS embedded as strings in JS
|
|
574
|
+
autoModules: true,
|
|
575
|
+
namedExports: true,
|
|
576
|
+
minifier: "cssnano",
|
|
577
|
+
});
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
**When to use inline mode:**
|
|
581
|
+
|
|
582
|
+
- Small CSS files where HTTP request overhead isn't worth it
|
|
583
|
+
- Critical CSS that must be available immediately
|
|
584
|
+
- Applications with dynamic CSS generation
|
|
585
|
+
- Components that need self-contained styles
|
|
586
|
+
|
|
587
|
+
### Emit Mode
|
|
588
|
+
|
|
589
|
+
Passes processed CSS through the build pipeline without injection or extraction:
|
|
590
|
+
|
|
591
|
+
```typescript
|
|
592
|
+
rollupCssPlugin({
|
|
593
|
+
mode: "emit", // CSS passed through build pipeline
|
|
594
|
+
autoModules: true,
|
|
595
|
+
minifier: "cssnano",
|
|
596
|
+
});
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
**Benefits:**
|
|
600
|
+
|
|
601
|
+
- **Build pipeline integration** - CSS can be processed by other Rollup plugins
|
|
602
|
+
- **Flexible output** - CSS can be transformed, bundled, or processed further
|
|
603
|
+
- **Custom handling** - Full control over how CSS is processed and output
|
|
604
|
+
- **Plugin ecosystem** - Leverage other Rollup plugins for CSS processing
|
|
605
|
+
- **No assumptions** - Plugin doesn't make assumptions about CSS output
|
|
606
|
+
|
|
607
|
+
**Trade-offs:**
|
|
608
|
+
|
|
609
|
+
- **Manual handling required** - Need to configure other plugins to handle CSS
|
|
610
|
+
- **Build complexity** - Requires understanding of Rollup plugin pipeline
|
|
611
|
+
- **No automatic optimization** - CSS optimization must be handled separately
|
|
612
|
+
- **Configuration overhead** - More setup required for complete CSS handling
|
|
613
|
+
|
|
614
|
+
**Use cases:**
|
|
615
|
+
|
|
616
|
+
- Custom CSS processing pipelines
|
|
617
|
+
- Integration with other Rollup plugins
|
|
618
|
+
- Applications requiring specific CSS output formats
|
|
619
|
+
- Build systems with custom CSS handling logic
|
|
620
|
+
- Development of CSS processing tools and plugins
|
|
621
|
+
|
|
622
|
+
## Mode Comparison
|
|
623
|
+
|
|
624
|
+
| Mode | Best For | Bundle Size | HTTP Requests | Caching | Complexity |
|
|
625
|
+
| ----------- | ------------------------- | ----------- | ------------- | -------- | ---------- |
|
|
626
|
+
| **Inject** | SPAs, dynamic injection | Larger JS | Single | Shared | Low |
|
|
627
|
+
| **Extract** | Production, CDN | Smaller JS | Multiple | Separate | Medium |
|
|
628
|
+
| **Inline** | Small files, critical CSS | Larger JS | Single | Shared | Low |
|
|
629
|
+
| **Emit** | Custom pipelines | Variable | Variable | Custom | High |
|
|
630
|
+
|
|
631
|
+
**Quick Decision Guide:**
|
|
632
|
+
|
|
633
|
+
- **Choose Inject** when you need guaranteed CSS availability and don't mind larger JS bundles
|
|
634
|
+
- **Choose Extract** when performance and caching are critical, especially for production
|
|
635
|
+
- **Choose Inline** when you have small CSS files and want to eliminate HTTP requests
|
|
636
|
+
- **Choose Emit** when you need full control over CSS processing and output
|
|
637
|
+
|
|
404
638
|
## CSS Modules Features
|
|
405
639
|
|
|
406
640
|
CSS Modules provide automatic class name scoping and TypeScript integration:
|
|
407
641
|
|
|
408
642
|
### Automatic TypeScript Declarations
|
|
643
|
+
|
|
409
644
|
- **Generated .d.ts files** for full IntelliSense support
|
|
410
|
-
- **Named exports** for individual class names
|
|
645
|
+
- **Named exports** for individual class names
|
|
411
646
|
- **Default export** with complete module interface
|
|
412
647
|
- **Build-time type checking** prevents runtime errors
|
|
413
648
|
|
|
414
649
|
### Scoped Class Names
|
|
650
|
+
|
|
415
651
|
- **Automatic hashing** prevents style conflicts
|
|
416
652
|
- **Deterministic naming** for consistent builds
|
|
417
653
|
- **Development-friendly** class names for debugging
|
|
418
654
|
|
|
419
655
|
### Integration Benefits
|
|
656
|
+
|
|
420
657
|
- **Zero configuration** - works out of the box with `.module.css` files
|
|
421
658
|
- **Watch mode support** - declarations update automatically
|
|
422
659
|
- **Build pipeline integration** - seamless Rollup integration
|
|
@@ -424,18 +661,21 @@ CSS Modules provide automatic class name scoping and TypeScript integration:
|
|
|
424
661
|
## Key Features
|
|
425
662
|
|
|
426
663
|
### Tailwind Integration
|
|
664
|
+
|
|
427
665
|
- **Tailwind CSS v4** - Latest version with PostCSS integration
|
|
428
666
|
- **Tailwind Oxide** - Rust-based engine for ultra-fast processing
|
|
429
667
|
- **JIT compilation** - Generate only the CSS you use
|
|
430
668
|
- **Smart purging** - Automatic unused style removal
|
|
431
669
|
|
|
432
670
|
### Preprocessor Support
|
|
671
|
+
|
|
433
672
|
- **PostCSS** - Modern CSS transformations with extensive plugin ecosystem
|
|
434
673
|
- **Sass/SCSS** - Popular CSS extension language with variables and mixins
|
|
435
674
|
- **Less** - Dynamic stylesheet language with variables and functions
|
|
436
675
|
- **Stylus** - Expressive, dynamic CSS preprocessor
|
|
437
676
|
|
|
438
677
|
### Performance Optimization
|
|
678
|
+
|
|
439
679
|
- **Multiple minifiers** - Choose between cssnano and LightningCSS
|
|
440
680
|
- **Source maps** - Full debugging support in development
|
|
441
681
|
- **Code splitting** - Efficient CSS bundling strategies
|
|
@@ -448,12 +688,12 @@ Leverage the extensive PostCSS ecosystem through configuration files:
|
|
|
448
688
|
```javascript
|
|
449
689
|
// postcss.config.js
|
|
450
690
|
export default {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
691
|
+
plugins: {
|
|
692
|
+
"@tailwindcss/postcss": {},
|
|
693
|
+
autoprefixer: {},
|
|
694
|
+
"postcss-nested": {},
|
|
695
|
+
},
|
|
696
|
+
};
|
|
457
697
|
```
|
|
458
698
|
|
|
459
699
|
The PostCSS loader automatically detects and uses your PostCSS configuration.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Plugin } from 'rollup';
|
|
2
|
-
import { S as StyleOptions } from './packem_shared/types-
|
|
3
|
-
export { A as AutoModules, E as ExtractedData, I as InjectOptions, a as InternalStyleOptions, L as LightningCSSOptions, P as PostCSSConfigLoaderOptions, b as PostCSSOptions } from './packem_shared/types-
|
|
2
|
+
import { S as StyleOptions } from './packem_shared/types-D3VQL1eC.js';
|
|
3
|
+
export { A as AutoModules, E as ExtractedData, I as InjectOptions, a as InternalStyleOptions, L as LightningCSSOptions, P as PostCSSConfigLoaderOptions, b as PostCSSOptions } from './packem_shared/types-D3VQL1eC.js';
|
|
4
4
|
import { Environment } from '@visulima/packem-share/types';
|
|
5
5
|
import 'cssnano';
|
|
6
6
|
import 'lightningcss';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{default as e}from"./packem_shared/cssModulesTypesPlugin-CjGroK2y.js";import{default as u}from"./packem_shared/rollupCssPlugin-CChaHsU3.js";export{e as cssModulesTypesPlugin,u as rollupCssPlugin};
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { c as Loader, d as LESSLoaderOptions } from '../../packem_shared/types-D3VQL1eC.js';
|
|
2
|
+
import 'cssnano';
|
|
3
|
+
import 'lightningcss';
|
|
4
|
+
import 'postcss';
|
|
5
|
+
import 'postcss-load-config';
|
|
6
|
+
import 'less';
|
|
7
|
+
import '@visulima/packem-share/types';
|
|
8
|
+
import 'sass';
|
|
9
|
+
import 'sass-embedded';
|
|
10
|
+
import 'stylus';
|
|
11
|
+
import '@visulima/packem-share/utils';
|
|
12
|
+
import 'rollup';
|
|
13
|
+
import 'source-map-js';
|
|
14
|
+
|
|
15
|
+
declare const loader: Loader<LESSLoaderOptions>;
|
|
16
|
+
|
|
17
|
+
export { LESSLoaderOptions, loader as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var l=(s,e)=>c(s,"name",{value:e,configurable:!0});import{dirname as u,normalize as d}from"@visulima/path";import f from"less";import{readFileSync as h}from"@visulima/fs";import{resolveAlias as g}from"@visulima/path/utils";import{resolve as y}from"../../packem_shared/resolve-anj9ucIq.js";import{normalizeUrl as F,getUrlOfPartial as v}from"../../packem_shared/hasModuleSpecifier-DIZeev_W.js";var b=Object.defineProperty,m=l((s,e)=>b(s,"name",{value:e,configurable:!0}),"i");const M=[".less",".css"],x=m((s,e)=>new class extends s.FileManager{supports(){return!0}async loadFile(r,a,t){const i=F(g(r,e)),o=v(i),n={baseDirs:[],caller:"Less importer",extensions:M};Array.isArray(t.paths)&&n.baseDirs.push(...t.paths),n.baseDirs.push(a);const p=y([o,i],n);return{contents:h(p),filename:p}}},"getStylesFileManager"),A=m(s=>({install(e,r){r.addFileManager(x(e,s))}}),"importer"),U={name:"less",async process({code:s,map:e}){const r=[A(this.alias)];this.options.plugins&&r.push(...this.options.plugins);const a=f.render,t=await a(s,{...this.options,filename:this.id,plugins:r,sourceMap:{outputSourceFiles:!0,sourceMapBasepath:u(this.id)}}),i=t.imports;for(const o of i)this.deps.add(d(o));return{code:t.css,map:t.map??e}},test:/\.less$/i};export{U as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Loader, L as LightningCSSOptions } from '../packem_shared/types-
|
|
1
|
+
import { c as Loader, L as LightningCSSOptions } from '../packem_shared/types-D3VQL1eC.js';
|
|
2
2
|
import 'cssnano';
|
|
3
3
|
import 'lightningcss';
|
|
4
4
|
import 'postcss';
|
|
@@ -14,4 +14,4 @@ import 'source-map-js';
|
|
|
14
14
|
|
|
15
15
|
declare const lightningCSSLoader: Loader<LightningCSSOptions>;
|
|
16
16
|
|
|
17
|
-
export
|
|
17
|
+
export { lightningCSSLoader as default };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{transform as r,browserslistToTargets as a}from"lightningcss";import{n as o}from"../packem_shared/ensure-auto-modules-BU3xWEjl.js";const l={name:"lightningCSS",async process({code:t,map:i}){let s=!1;typeof this.options.modules=="boolean"?s=this.options.modules:typeof this.options.modules=="object"&&(s=o(this.options.modules.include,this.id)),this.autoModules&&this.options.modules===void 0&&(s=o(this.autoModules,this.id));const e=r({...this.options,code:Buffer.from(t),cssModules:this.options.modules??s,filename:this.id,inputSourceMap:i,minify:!1,sourceMap:!this.sourceMap,targets:a(this.browserTargets)});return e.warnings.length>0&&this.logger.warn({message:`warnings when transforming css:
|
|
2
|
+
${e.warnings.map(n=>n.message).join(`
|
|
3
|
+
`)}`}),{code:e.code.toString(),map:e.map?JSON.parse(Buffer.from(e.map).toString()):void 0,moduleSideEffects:s||typeof this.inject=="object"&&this.inject.treeshakeable?!1:"no-treeshake"}},test:/\.css$/i};export{l as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Loader, a as InternalStyleOptions } from '../../packem_shared/types-
|
|
1
|
+
import { c as Loader, a as InternalStyleOptions } from '../../packem_shared/types-D3VQL1eC.js';
|
|
2
2
|
import 'cssnano';
|
|
3
3
|
import 'lightningcss';
|
|
4
4
|
import 'postcss';
|
|
@@ -14,4 +14,4 @@ import 'source-map-js';
|
|
|
14
14
|
|
|
15
15
|
declare const loader: Loader<NonNullable<InternalStyleOptions["postcss"]>>;
|
|
16
16
|
|
|
17
|
-
export
|
|
17
|
+
export { loader as default };
|