@@ -103,7 +103,7 @@ let previous: {
103
103
104
104
let tailwind : Awaited < ReturnType < typeof init_tailwind > > ;
105
105
106
- async function init_tailwind ( ) {
106
+ async function init_tailwind ( user_css = '' ) {
107
107
const tailwindcss = await import ( 'tailwindcss' ) ;
108
108
109
109
const { default : tailwind_preflight } = await import ( 'tailwindcss/preflight.css?raw' ) ;
@@ -120,7 +120,8 @@ async function init_tailwind() {
120
120
`@layer theme, base, components, utilities;` ,
121
121
`@import "tailwindcss/theme.css" layer(theme);` ,
122
122
`@import "tailwindcss/preflight.css" layer(base);` ,
123
- `@import "tailwindcss/utilities.css" layer(utilities);`
123
+ `@import "tailwindcss/utilities.css" layer(utilities);` ,
124
+ user_css
124
125
] . join ( '\n' ) ;
125
126
126
127
return await tailwindcss . compile ( tailwind_base , {
@@ -412,6 +413,8 @@ async function get_bundle(
412
413
} ;
413
414
414
415
const key = JSON . stringify ( options ) ;
416
+ const handled_css_ids = new Set < string > ( ) ;
417
+ let user_css = '' ;
415
418
416
419
bundle = await rollup ( {
417
420
input : './__entry.js' ,
@@ -429,6 +432,23 @@ async function get_bundle(
429
432
replace ( {
430
433
'process.env.NODE_ENV' : JSON . stringify ( 'production' )
431
434
} ) ,
435
+ {
436
+ name : 'css' ,
437
+ transform ( code , id ) {
438
+ if ( id . endsWith ( '.css' ) ) {
439
+ if ( ! handled_css_ids . has ( id ) ) {
440
+ handled_css_ids . add ( id ) ;
441
+ // We don't handle imports in the user CSS right now, so we remove them
442
+ // to avoid errors in e.g. the Tailwind compiler
443
+ user_css += '\n' + code . replace ( / @ i m p o r t \s + [ " ' ] [ ^ " ' ] + [ " ' ] [ ^ ; ] * ; / g, '' ) ;
444
+ }
445
+ return {
446
+ code : '' ,
447
+ map : null
448
+ } ;
449
+ }
450
+ }
451
+ } ,
432
452
options . tailwind && {
433
453
name : 'tailwind-extract' ,
434
454
transform ( code , id ) {
@@ -455,9 +475,11 @@ async function get_bundle(
455
475
456
476
return {
457
477
bundle,
458
- tailwind : options . tailwind
459
- ? ( tailwind ?? ( await init_tailwind ( ) ) ) . build ( tailwind_candidates )
460
- : undefined ,
478
+ css : options . tailwind
479
+ ? ( tailwind ?? ( await init_tailwind ( user_css ) ) ) . build ( tailwind_candidates )
480
+ : user_css
481
+ ? user_css
482
+ : null ,
461
483
imports : Array . from ( imports ) ,
462
484
error : null ,
463
485
warnings,
@@ -585,7 +607,7 @@ async function bundle(
585
607
error : null ,
586
608
client : client_result ,
587
609
server : server_result ,
588
- tailwind : client . tailwind ,
610
+ css : client . css ,
589
611
imports : client . imports
590
612
} ;
591
613
} catch ( err ) {
@@ -598,7 +620,7 @@ async function bundle(
598
620
error : { ...e , message : e . message } , // not all Svelte versions return an enumerable message property
599
621
client : null ,
600
622
server : null ,
601
- tailwind : null ,
623
+ css : null ,
602
624
imports : null
603
625
} ;
604
626
}
0 commit comments