UNPKG

803 BJavaScriptView Raw
1exports.name = 'builtin:config-image'
2
3exports.apply = api => {
4 api.hook('onCreateWebpackConfig', config => {
5 const inlineImageMaxSize = 5000 // 5 KB
6
7 const filename = api.webpackUtils.fileNames.image
8
9 config.module
10 .rule('image')
11 .test([/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/, /\.webp$/])
12 .use('url-loader')
13 .loader('url-loader')
14 .options({
15 name: filename,
16 // inline the file if < max size
17 limit: inlineImageMaxSize
18 })
19
20 config.module
21 .rule('svg')
22 .test(/\.(svg)(\?.*)?$/)
23 .use('file-loader')
24 // SVG files use file-loader directly, why?
25 // See https://github.com/facebookincubator/create-react-app/pull/1180
26 .loader('file-loader')
27 .options({
28 name: filename
29 })
30 })
31}