webpack.config.js
1.09 KB
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
const TerserPlugin = require('terser-webpack-plugin-legacy');
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
const path = require('path');
module.exports = (webpackConfig, env) => {
const data = webpackConfig.resolve.alias;
webpackConfig.resolve.alias = {
'@': `${__dirname}/src`,
...data,
};
webpackConfig.module.rules.forEach((item) => {
if (String(item.loader).indexOf('url-loader') > -1) {
// item.exclude.push(/\.svg$/);
item.exclude.push(path.resolve(__dirname, './src/assets/icons'));
}
});
webpackConfig.module.rules = ([
{
test: /\.svg$/,
include: path.resolve(__dirname, './src/assets/icons'),
use: [
{
loader: 'svg-sprite-loader',
},
],
},
]).concat(webpackConfig.module.rules);
webpackConfig.plugins = webpackConfig.plugins.concat([
new SpriteLoaderPlugin(),
]);
if (process.env.NODE_ENV === 'production') {
webpackConfig.plugins.splice(
3,
1,
new TerserPlugin({
cache: true,
parallel: true,
}),
);
}
return webpackConfig;
};