Skip to content

Commit 51e29b8

Browse files
committed
chore: update
1 parent 45848b2 commit 51e29b8

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

examples/react-component-bundle/rslib.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export default defineConfig({
77
{
88
format: 'esm',
99
dts: true,
10-
// syntax: 'es5',
1110
output: {
1211
distPath: {
1312
root: './dist/esm',
@@ -16,7 +15,6 @@ export default defineConfig({
1615
},
1716
{
1817
format: 'cjs',
19-
syntax: 'es5',
2018
dts: true,
2119
output: {
2220
distPath: {

packages/core/src/asset/assetConfig.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,47 @@ import type { EnvironmentConfig, RsbuildPlugin } from '@rsbuild/core';
22
import type { Format } from '../types';
33
import { LibAssetExtractPlugin } from './LibAssetExtractPlugin';
44

5-
const PLUGIN_NAME = 'rsbuild:lib-asset-bundleless';
5+
const PLUGIN_NAME = 'rsbuild:lib-asset';
66

77
const RSBUILD_SVGR_PLUGIN_NAME = 'rsbuild:svgr';
88
const pluginLibAsset = ({ bundle }: { bundle: boolean }): RsbuildPlugin => ({
99
name: PLUGIN_NAME,
1010
pre: [RSBUILD_SVGR_PLUGIN_NAME],
1111
setup(api) {
1212
api.modifyBundlerChain((config, { CHAIN_ID }) => {
13-
// only support transform the svg asset to mixedImport svgr file
14-
// remove issuer to make every svg asset is transformed
1513
const isUsingSvgr = Boolean(
1614
config.module
1715
.rule(CHAIN_ID.RULE.SVG)
1816
.oneOf(CHAIN_ID.RULE.SVG)
1917
.uses.has(CHAIN_ID.USE.SVGR),
2018
);
21-
if (isUsingSvgr) {
19+
if (isUsingSvgr && !bundle) {
20+
// in bundleless, only support transform the svg asset to mixedImport svgr file
21+
// remove issuer to make every svg asset is transformed
2222
const rule = config.module
2323
.rule(CHAIN_ID.RULE.SVG)
24-
.oneOf(CHAIN_ID.RULE.SVG);
24+
.oneOf(CHAIN_ID.ONE_OF.SVG);
2525
rule.issuer([]);
2626
}
2727
config
2828
.plugin(LibAssetExtractPlugin.name)
2929
.use(LibAssetExtractPlugin, [{ bundle, isUsingSvgr }]);
30+
31+
if (bundle) {
32+
// preserve './' in css url
33+
// https://github.com/web-infra-dev/rspack/pull/8946
34+
config.plugins.get(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT)?.tap((options) => {
35+
if (bundle) {
36+
return [
37+
{
38+
...options[0],
39+
enforceRelative: true,
40+
},
41+
];
42+
}
43+
return options;
44+
});
45+
}
3046
});
3147
},
3248
});
@@ -43,13 +59,7 @@ export const composeAssetConfig = (
4359
dataUriLimit: 0, // default: no inline asset
4460
assetPrefix: 'auto',
4561
},
46-
tools: {
47-
rspack: {
48-
plugins: [
49-
new LibAssetExtractPlugin({ bundle: true, isUsingSvgr: false }),
50-
],
51-
},
52-
},
62+
plugins: [pluginLibAsset({ bundle: true })],
5363
};
5464
}
5565
return {

packages/core/src/css/LibCssExtractPlugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
6767
const undoPath = getUndoPath(
6868
name,
6969
compilation.outputOptions.path!,
70-
false,
70+
// https://github.com/web-infra-dev/rspack/pull/8946
71+
true,
7172
);
7273
replace(`${ABSOLUTE_PUBLIC_PATH}${AUTO_PUBLIC_PATH}`, undoPath);
7374
replace(ABSOLUTE_PUBLIC_PATH, '');

packages/core/tests/__snapshots__/config.test.ts.snap

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
114114
"name": "rsbuild:format",
115115
"setup": [Function],
116116
},
117+
{
118+
"name": "rsbuild:lib-asset",
119+
"pre": [
120+
"rsbuild:svgr",
121+
],
122+
"setup": [Function],
123+
},
117124
{
118125
"name": "rsbuild:lib-entry-chunk",
119126
"setup": [Function],
@@ -214,17 +221,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
214221
{
215222
"externalsType": "module-import",
216223
},
217-
{
218-
"plugins": [
219-
LibAssetExtractPlugin {
220-
"name": "LIB_ASSET_EXTRACT_PLUGIN",
221-
"options": {
222-
"bundle": true,
223-
"isUsingSvgr": false,
224-
},
225-
},
226-
],
227-
},
228224
{
229225
"plugins": [
230226
EntryChunkPlugin {
@@ -369,6 +365,13 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
369365
"name": "rsbuild:cjs-import-meta-url-shim",
370366
"setup": [Function],
371367
},
368+
{
369+
"name": "rsbuild:lib-asset",
370+
"pre": [
371+
"rsbuild:svgr",
372+
],
373+
"setup": [Function],
374+
},
372375
{
373376
"name": "rsbuild:lib-entry-chunk",
374377
"setup": [Function],
@@ -461,17 +464,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
461464
{
462465
"externalsType": "commonjs-import",
463466
},
464-
{
465-
"plugins": [
466-
LibAssetExtractPlugin {
467-
"name": "LIB_ASSET_EXTRACT_PLUGIN",
468-
"options": {
469-
"bundle": true,
470-
"isUsingSvgr": false,
471-
},
472-
},
473-
],
474-
},
475467
{
476468
"plugins": [
477469
EntryChunkPlugin {

tests/integration/asset/index.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ test('set the assets output path', async () => {
137137
test('set the assets public path', async () => {
138138
const fixturePath = join(__dirname, 'public-path');
139139
const { contents } = await buildAndGetResults({ fixturePath });
140-
141140
// umd should preserve '__webpack_require__.p'
142141
const { content: indexUmdJs } = queryContent(contents.umd!, /index\.js/);
143142

0 commit comments

Comments
 (0)