Skip to content

Commit 934c849

Browse files
committed
chore: update
1 parent 2b08425 commit 934c849

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

packages/core/src/css/LibCssExtractPlugin.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { type Rspack, rspack } from '@rsbuild/core';
2-
import { RSLIB_CSS_ENTRY_FLAG } from './cssConfig';
32
import {
43
ABSOLUTE_PUBLIC_PATH,
54
AUTO_PUBLIC_PATH,
@@ -20,21 +19,6 @@ class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
2019
}
2120

2221
apply(compiler: Rspack.Compiler): void {
23-
// 1. mark and remove the normal css asset
24-
// 2. preserve CSS Modules asset
25-
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
26-
compilation.hooks.chunkAsset.tap(pluginName, (_chunk, filename) => {
27-
const asset = compilation.getAsset(filename);
28-
if (!asset) {
29-
return;
30-
}
31-
const needRemove = Boolean(asset.name.match(RSLIB_CSS_ENTRY_FLAG));
32-
if (needRemove) {
33-
compilation.deleteAsset(filename);
34-
}
35-
});
36-
});
37-
3822
/**
3923
* The following code is modified based on
4024
* https://github.com/webpack-contrib/mini-css-extract-plugin/blob/3effaa0319bad5cc1bf0ae760553bf7abcbc35a4/src/index.js#L1597

packages/core/src/css/cssConfig.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,29 @@ export async function cssExternalHandler(
130130

131131
const PLUGIN_NAME = 'rsbuild:lib-css';
132132

133+
// 1. replace CssExtractPlugin.loader with libCssExtractLoader
134+
// 2. replace CssExtractPlugin with LibCssExtractPlugin
133135
const pluginLibCss = (
134136
rootDir: string,
135137
banner?: string,
136138
footer?: string,
137139
): RsbuildPlugin => ({
138140
name: PLUGIN_NAME,
139141
setup(api) {
142+
// 1. mark and remove the "normal css asset" (contain RSLIB_CSS_ENTRY_FLAG)
143+
// 2. preserve CSS Modules asset
144+
api.processAssets(
145+
{ stage: 'additional', targets: ['web', 'node'] },
146+
({ assets, compilation, environment }) => {
147+
for (const key of Object.keys(assets)) {
148+
console.log(key, 2222222, environment);
149+
if (key.match(RSLIB_CSS_ENTRY_FLAG)) {
150+
compilation.deleteAsset(key);
151+
}
152+
}
153+
},
154+
);
155+
140156
api.modifyBundlerChain((config, { CHAIN_ID }) => {
141157
let isUsingCssExtract = false;
142158
for (const ruleId of [

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "node-css-bundle-false-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from '@rslib/core';
2+
import { generateBundleCjsConfig, generateBundleEsmConfig } from 'test-helper';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig({ bundle: false }),
7+
generateBundleCjsConfig({ bundle: false }),
8+
],
9+
source: {
10+
entry: {
11+
index: ['../__fixtures__/basic/src/**/*.css'],
12+
},
13+
},
14+
});

0 commit comments

Comments
 (0)