Skip to content

Commit ea03876

Browse files
committed
fix
1 parent b406b78 commit ea03876

File tree

1 file changed

+16
-10
lines changed
  • packages/core/src/plugins

1 file changed

+16
-10
lines changed

packages/core/src/plugins/css.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,19 +227,16 @@ const getPostcssLoaderOptions = async ({
227227

228228
const 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,7 +415,6 @@ export const pluginCss = (): RsbuildPlugin => ({
408415
const localIdentName = getCSSModulesLocalIdentName(config, isProd);
409416
const cssLoaderOptions = getCSSLoaderOptions({
410417
config,
411-
importLoaders,
412418
localIdentName,
413419
emitCss,
414420
});
@@ -421,12 +427,12 @@ export const pluginCss = (): RsbuildPlugin => ({
421427
...cssLoaderOptions,
422428
exportType: 'string',
423429
modules: false,
430+
importLoaders: importLoaders.inline,
424431
};
425-
} else if (!emitCss && cssLoaderOptions.importLoaders) {
426-
// If emitCss is disabled, correct importLoaders number for normal CSS rule
432+
} else {
427433
finalOptions = {
428434
...cssLoaderOptions,
429-
importLoaders: cssLoaderOptions.importLoaders - 1,
435+
importLoaders: importLoaders.normal,
430436
};
431437
}
432438
rule.use(CHAIN_ID.USE.CSS).options(finalOptions);

0 commit comments

Comments
 (0)