@@ -227,19 +227,16 @@ const getPostcssLoaderOptions = async ({
227227
228228const getCSSLoaderOptions = ( {
229229 config,
230- importLoaders,
231230 localIdentName,
232231 emitCss,
233232} : {
234233 config : NormalizedEnvironmentConfig ;
235- importLoaders : number ;
236234 localIdentName : string ;
237235 emitCss : boolean ;
238236} ) => {
239237 const { cssModules } = config . output ;
240238
241239 const defaultOptions : CSSLoaderOptions = {
242- importLoaders,
243240 modules : {
244241 ...cssModules ,
245242 localIdentName,
@@ -328,7 +325,10 @@ export const pluginCss = (): RsbuildPlugin => ({
328325 }
329326
330327 // Number of loaders applied before css-loader for `@import` at-rules
331- let importLoaders = 0 ;
328+ const importLoaders = {
329+ normal : 0 ,
330+ inline : 0 ,
331+ } ;
332332
333333 // Update the normal CSS rule and the inline CSS rule
334334 const updateRules = (
@@ -351,7 +351,10 @@ export const pluginCss = (): RsbuildPlugin => ({
351351 api . context . bundlerType === 'rspack' &&
352352 config . tools . lightningcssLoader !== false
353353 ) {
354- importLoaders ++ ;
354+ if ( emitCss ) {
355+ importLoaders . normal ++ ;
356+ }
357+ importLoaders . inline ++ ;
355358
356359 const { minifyCss } = parseMinifyOptions ( config ) ;
357360
@@ -390,7 +393,11 @@ export const pluginCss = (): RsbuildPlugin => ({
390393 typeof postcssLoaderOptions . postcssOptions === 'function' ||
391394 postcssLoaderOptions . postcssOptions ?. plugins ?. length
392395 ) {
393- importLoaders ++ ;
396+ if ( emitCss ) {
397+ importLoaders . normal ++ ;
398+ }
399+ importLoaders . inline ++ ;
400+
394401 const postcssLoaderPath = getCompiledPath ( 'postcss-loader' ) ;
395402
396403 updateRules (
@@ -408,21 +415,27 @@ export const pluginCss = (): RsbuildPlugin => ({
408415 const localIdentName = getCSSModulesLocalIdentName ( config , isProd ) ;
409416 const cssLoaderOptions = getCSSLoaderOptions ( {
410417 config,
411- importLoaders,
412418 localIdentName,
413419 emitCss,
414420 } ) ;
415421
416422 updateRules ( ( rule , type ) => {
417- rule . use ( CHAIN_ID . USE . CSS ) . options (
418- type === 'inline'
419- ? ( {
420- ...cssLoaderOptions ,
421- exportType : 'string' ,
422- modules : false ,
423- } satisfies CSSLoaderOptions )
424- : cssLoaderOptions ,
425- ) ;
423+ let finalOptions = cssLoaderOptions ;
424+
425+ if ( type === 'inline' ) {
426+ finalOptions = {
427+ ...cssLoaderOptions ,
428+ exportType : 'string' ,
429+ modules : false ,
430+ importLoaders : importLoaders . inline ,
431+ } ;
432+ } else {
433+ finalOptions = {
434+ ...cssLoaderOptions ,
435+ importLoaders : importLoaders . normal ,
436+ } ;
437+ }
438+ rule . use ( CHAIN_ID . USE . CSS ) . options ( finalOptions ) ;
426439
427440 // CSS imports should always be treated as sideEffects
428441 rule . sideEffects ( true ) ;
0 commit comments