@@ -103,7 +103,7 @@ let previous: {
103103
104104let tailwind : Awaited < ReturnType < typeof init_tailwind > > ;
105105
106- async function init_tailwind ( ) {
106+ async function init_tailwind ( user_css = '' ) {
107107 const tailwindcss = await import ( 'tailwindcss' ) ;
108108
109109 const { default : tailwind_preflight } = await import ( 'tailwindcss/preflight.css?raw' ) ;
@@ -120,7 +120,8 @@ async function init_tailwind() {
120120 `@layer theme, base, components, utilities;` ,
121121 `@import "tailwindcss/theme.css" layer(theme);` ,
122122 `@import "tailwindcss/preflight.css" layer(base);` ,
123- `@import "tailwindcss/utilities.css" layer(utilities);`
123+ `@import "tailwindcss/utilities.css" layer(utilities);` ,
124+ user_css
124125 ] . join ( '\n' ) ;
125126
126127 return await tailwindcss . compile ( tailwind_base , {
@@ -412,6 +413,8 @@ async function get_bundle(
412413 } ;
413414
414415 const key = JSON . stringify ( options ) ;
416+ const handled_css_ids = new Set < string > ( ) ;
417+ let user_css = '' ;
415418
416419 bundle = await rollup ( {
417420 input : './__entry.js' ,
@@ -429,6 +432,23 @@ async function get_bundle(
429432 replace ( {
430433 'process.env.NODE_ENV' : JSON . stringify ( 'production' )
431434 } ) ,
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+ } ,
432452 options . tailwind && {
433453 name : 'tailwind-extract' ,
434454 transform ( code , id ) {
@@ -455,9 +475,11 @@ async function get_bundle(
455475
456476 return {
457477 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 ,
461483 imports : Array . from ( imports ) ,
462484 error : null ,
463485 warnings,
@@ -585,7 +607,7 @@ async function bundle(
585607 error : null ,
586608 client : client_result ,
587609 server : server_result ,
588- tailwind : client . tailwind ,
610+ css : client . css ,
589611 imports : client . imports
590612 } ;
591613 } catch ( err ) {
@@ -598,7 +620,7 @@ async function bundle(
598620 error : { ...e , message : e . message } , // not all Svelte versions return an enumerable message property
599621 client : null ,
600622 server : null ,
601- tailwind : null ,
623+ css : null ,
602624 imports : null
603625 } ;
604626 }
0 commit comments