@@ -2,31 +2,47 @@ import type { EnvironmentConfig, RsbuildPlugin } from '@rsbuild/core';
22import type { Format } from '../types' ;
33import { LibAssetExtractPlugin } from './LibAssetExtractPlugin' ;
44
5- const PLUGIN_NAME = 'rsbuild:lib-asset-bundleless ' ;
5+ const PLUGIN_NAME = 'rsbuild:lib-asset' ;
66
77const RSBUILD_SVGR_PLUGIN_NAME = 'rsbuild:svgr' ;
88const 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 {
0 commit comments