File tree 6 files changed +91
-1
lines changed
fixtures/kitchensink/src/features/webpack
6 files changed +91
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,16 @@ const path = require('path');
15
15
16
16
module . exports = {
17
17
process ( src , filename ) {
18
- return `module.exports = ${ JSON . stringify ( path . basename ( filename ) ) } ;` ;
18
+ const assetFilename = JSON . stringify ( path . basename ( filename ) ) ;
19
+
20
+ if ( filename . match ( / \. s v g $ / ) ) {
21
+ return `module.exports = {
22
+ __esModule: true,
23
+ default: ${ assetFilename } ,
24
+ ReactComponent: () => ${ assetFilename } ,
25
+ };` ;
26
+ }
27
+
28
+ return `module.exports = ${ assetFilename } ;` ;
19
29
} ,
20
30
} ;
Original file line number Diff line number Diff line change @@ -262,6 +262,31 @@ module.exports = {
262
262
} ,
263
263
] ,
264
264
} ,
265
+ // Allows you to use two kinds of imports for SVG:
266
+ // import logoUrl from './logo.svg'; gives you the URL.
267
+ // import { ReactComponent as Logo } from './logo.svg'; gives you a component.
268
+ {
269
+ test : / \. s v g $ / ,
270
+ use : [
271
+ {
272
+ loader : require . resolve ( 'babel-loader' ) ,
273
+ options : {
274
+ // @remove -on-eject-begin
275
+ babelrc : false ,
276
+ presets : [ require . resolve ( 'babel-preset-react-app' ) ] ,
277
+ // @remove -on-eject-end
278
+ cacheDirectory : true ,
279
+ } ,
280
+ } ,
281
+ require . resolve ( 'svgr/webpack' ) ,
282
+ {
283
+ loader : require . resolve ( 'file-loader' ) ,
284
+ options : {
285
+ name : 'static/media/[name].[hash:8].[ext]' ,
286
+ } ,
287
+ } ,
288
+ ] ,
289
+ } ,
265
290
// "file" loader makes sure those assets get served by WebpackDevServer.
266
291
// When you `import` an asset, you get its (virtual) filename.
267
292
// In production, they would get copied to the `build` folder.
Original file line number Diff line number Diff line change @@ -304,6 +304,31 @@ module.exports = {
304
304
) ,
305
305
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
306
306
} ,
307
+ // Allows you to use two kinds of imports for SVG:
308
+ // import logoUrl from './logo.svg'; gives you the URL.
309
+ // import { ReactComponent as Logo } from './logo.svg'; gives you a component.
310
+ {
311
+ test : / \. s v g $ / ,
312
+ use : [
313
+ {
314
+ loader : require . resolve ( 'babel-loader' ) ,
315
+ options : {
316
+ // @remove -on-eject-begin
317
+ babelrc : false ,
318
+ presets : [ require . resolve ( 'babel-preset-react-app' ) ] ,
319
+ // @remove -on-eject-end
320
+ cacheDirectory : true ,
321
+ } ,
322
+ } ,
323
+ require . resolve ( 'svgr/webpack' ) ,
324
+ {
325
+ loader : require . resolve ( 'file-loader' ) ,
326
+ options : {
327
+ name : 'static/media/[name].[hash:8].[ext]' ,
328
+ } ,
329
+ } ,
330
+ ] ,
331
+ } ,
307
332
// "file" loader makes sure assets end up in the `build` folder.
308
333
// When you `import` an asset, you get its filename.
309
334
// This loader doesn't use a "test" so it will catch all modules
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react' ;
9
+ import { ReactComponent as Logo } from './assets/logo.svg' ;
10
+
11
+ export default ( ) => < Logo /> ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react' ;
9
+ import ReactDOM from 'react-dom' ;
10
+ import SvgComponent from './SvgComponent' ;
11
+
12
+ describe ( 'svg component' , ( ) => {
13
+ it ( 'renders without crashing' , ( ) => {
14
+ const div = document . createElement ( 'div' ) ;
15
+ ReactDOM . render ( < SvgComponent /> , div ) ;
16
+ expect ( div . textContent ) . toBe ( 'logo.svg' ) ;
17
+ } ) ;
18
+ } ) ;
Original file line number Diff line number Diff line change 54
54
"raf" : " 3.4.0" ,
55
55
"react-dev-utils" : " ^5.0.0" ,
56
56
"style-loader" : " 0.19.1" ,
57
+ "svgr" : " 1.6.0" ,
57
58
"sw-precache-webpack-plugin" : " 0.11.4" ,
58
59
"thread-loader" : " 1.1.2" ,
59
60
"uglifyjs-webpack-plugin" : " 1.1.6" ,
You can’t perform that action at this time.
0 commit comments