-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
57 lines (52 loc) · 1.32 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const path = require('path');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
const SpritesmithPlugin = require('webpack-spritesmith');
const spritesmithPlugin = new SpritesmithPlugin({
src: {
cwd: path.resolve(__dirname, 'src/sprites/png'),
glob: '*.png',
},
target: {
image: path.resolve(__dirname, 'src/.sprites/sprites.png'),
css: path.resolve(__dirname, 'src/.sprites/sprites.less'),
},
apiOptions: {
cssImageRef: 'sprites.png',
},
});
/* eslint-disable no-param-reassign */
module.exports = (webpackConfig) => {
webpackConfig.module.rules.forEach((item) => {
if (-1 < String(item.loader).indexOf('url-loader')) {
item.exclude.push(/\.svg$/);
}
});
webpackConfig.plugins = webpackConfig.plugins.concat([
new SpriteLoaderPlugin(),
spritesmithPlugin,
]);
webpackConfig.module.rules = ([
{
test: /\.svg$/,
use: [
{
loader: 'svg-sprite-loader',
options: {
extract: true,
},
},
{
loader: 'svgo-loader',
options: {
plugins: [
{ removeTitle: true },
{ removeStyleElement: true },
],
},
},
],
},
]).concat(webpackConfig.module.rules);
return webpackConfig;
};
/* eslint-enable */