@@ -13,14 +13,15 @@ const RSBUILD_SVGR_PLUGIN_NAME = 'rsbuild:svgr';
13
13
/**
14
14
* Be compatible to css-extract importModule and experimentalLibPreserveExports
15
15
* when set experimentalLibPreserveExports to true, the css-loader result can not executed in node side, so clone the assets rule
16
- * 1. js assets: original rule set issuer and experimentalLibPreserveExports: true
17
- * 2. css assets: a copy of original rule
16
+ * 1. js assets: original rule set issuer and experimentalLibPreserveExports: true, `import url from './foo.svg'`
17
+ * 2. css assets: a copy of original rule, `url('./foo.svg')`
18
18
*/
19
19
const pluginLibAsset = ( { bundle } : { bundle : boolean } ) : RsbuildPlugin => ( {
20
20
name : PLUGIN_NAME ,
21
21
pre : [ RSBUILD_SVGR_PLUGIN_NAME ] ,
22
22
setup ( api ) {
23
23
api . modifyBundlerChain ( ( config , { CHAIN_ID } ) => {
24
+ // for separating css assets and js assets
24
25
// 1. modify svg rule first, svg is special because of svgr
25
26
const svgAssetRule = config . module . rules
26
27
. get ( CHAIN_ID . RULE . SVG )
@@ -92,14 +93,17 @@ const pluginLibAsset = ({ bundle }: { bundle: boolean }): RsbuildPlugin => ({
92
93
}
93
94
94
95
// for svgr
96
+ const isUsingSvgr : boolean = config . module
97
+ . rule ( CHAIN_ID . RULE . SVG )
98
+ . oneOf ( CHAIN_ID . RULE . SVG )
99
+ . uses . has ( CHAIN_ID . USE . SVGR ) ;
100
+ const isUsingSvgrUrlLoader = config . module
101
+ . rule ( CHAIN_ID . RULE . SVG )
102
+ . oneOf ( CHAIN_ID . ONE_OF . SVG )
103
+ . uses . has ( CHAIN_ID . USE . URL ) ;
104
+
95
105
// 1. remove __webpack_require__.p in svgr url-loader and file-loader
96
- const isUsingSvgr = Boolean (
97
- config . module
98
- . rule ( CHAIN_ID . RULE . SVG )
99
- . oneOf ( CHAIN_ID . RULE . SVG )
100
- . uses . has ( CHAIN_ID . USE . SVGR ) ,
101
- ) ;
102
- if ( isUsingSvgr ) {
106
+ if ( isUsingSvgr && isUsingSvgrUrlLoader ) {
103
107
const urlLoaderRule = config . module
104
108
. rule ( CHAIN_ID . RULE . SVG )
105
109
. oneOf ( CHAIN_ID . ONE_OF . SVG )
@@ -113,8 +117,8 @@ const pluginLibAsset = ({ bundle }: { bundle: boolean }): RsbuildPlugin => ({
113
117
} ) ;
114
118
config . plugin ( LibSvgrPatchPlugin . name ) . use ( LibSvgrPatchPlugin , [ ] ) ;
115
119
}
116
- // 2. in bundleless, only support transform the svg asset to mixedImport svgr file
117
- // remove issuer to make every svg asset is transformed
120
+ // 2. in bundleless, do not support queryImport
121
+ // remove issuer to make every svg asset is transformed by svgr-loader
118
122
if ( ! bundle ) {
119
123
if ( isUsingSvgr ) {
120
124
const rule = config . module
0 commit comments