File tree Expand file tree Collapse file tree 4 files changed +52
-8
lines changed
e2e/cases/svg/svgr-disable-emit-asset Expand file tree Collapse file tree 4 files changed +52
-8
lines changed Original file line number Diff line number Diff line change
1
+ import { expect , test } from '@playwright/test' ;
2
+ import { build , gotoPage } from '@e2e/helper' ;
3
+
4
+ test ( 'should import svg with SVGR plugin and query URL correctly' , async ( ) => {
5
+ const rsbuild = await build ( {
6
+ cwd : __dirname ,
7
+ } ) ;
8
+
9
+ const files = await rsbuild . unwrapOutputJSON ( ) ;
10
+ const filenames = Object . keys ( files ) ;
11
+
12
+ expect (
13
+ filenames . some ( ( filename ) =>
14
+ filename . includes ( 'dist/static/svg/mobile.svg' ) ,
15
+ ) ,
16
+ ) . toBeFalsy ( ) ;
17
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { defineConfig } from '@rsbuild/core' ;
2
+ import { pluginReact } from '@rsbuild/plugin-react' ;
3
+ import { pluginSvgr } from '@rsbuild/plugin-svgr' ;
4
+
5
+ export default defineConfig ( {
6
+ plugins : [
7
+ pluginReact ( ) ,
8
+ pluginSvgr ( {
9
+ svgrOptions : {
10
+ exportType : 'default' ,
11
+ } ,
12
+ } ) ,
13
+ ] ,
14
+ output : {
15
+ filenameHash : false ,
16
+ emitAssets : ( ) => false ,
17
+ } ,
18
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import svgImg from '@assets/mobile.svg?url' ;
2
+
3
+ console . log ( svgImg ) ;
Original file line number Diff line number Diff line change @@ -75,8 +75,18 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
75
75
const maxSize =
76
76
typeof dataUriLimit === 'number' ? dataUriLimit : dataUriLimit . svg ;
77
77
78
- // delete Rsbuild builtin SVG rules
79
- chain . module . rules . delete ( CHAIN_ID . RULE . SVG ) ;
78
+ let generatorOptions : Rspack . GeneratorOptionsByModuleType [ 'asset/resource' ] =
79
+ { } ;
80
+
81
+ if ( chain . module . rules . has ( CHAIN_ID . RULE . SVG ) ) {
82
+ generatorOptions = chain . module . rules
83
+ . get ( CHAIN_ID . RULE . SVG )
84
+ . oneOfs . get ( CHAIN_ID . ONE_OF . SVG_URL )
85
+ . get ( 'generator' ) ;
86
+
87
+ // delete Rsbuild builtin SVG rules
88
+ chain . module . rules . delete ( CHAIN_ID . RULE . SVG ) ;
89
+ }
80
90
81
91
const rule = chain . module . rule ( CHAIN_ID . RULE . SVG ) . test ( SVG_REGEX ) ;
82
92
@@ -93,9 +103,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
93
103
. oneOf ( CHAIN_ID . ONE_OF . SVG_URL )
94
104
. type ( 'asset/resource' )
95
105
. resourceQuery ( / ( _ _ i n l i n e = f a l s e | u r l ) / )
96
- . set ( 'generator' , {
97
- filename : outputName ,
98
- } ) ;
106
+ . set ( 'generator' , generatorOptions ) ;
99
107
100
108
// force to inline: "foo.svg?inline"
101
109
rule
@@ -169,9 +177,7 @@ export const pluginSvgr = (options: PluginSvgrOptions = {}): RsbuildPlugin => ({
169
177
maxSize,
170
178
} ,
171
179
} )
172
- . set ( 'generator' , {
173
- filename : outputName ,
174
- } ) ;
180
+ . set ( 'generator' , generatorOptions ) ;
175
181
176
182
// apply current JS transform rule to SVGR rules
177
183
const jsRule = chain . module . rules . get ( CHAIN_ID . RULE . JS ) ;
You can’t perform that action at this time.
0 commit comments