-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.update.js
92 lines (89 loc) · 2.44 KB
/
webpack.config.update.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const ExtractTextPlugin = require('extract-text-webpack-plugin'); // eslint-disable-line
const webpack = require('webpack'); // eslint-disable-line
const IS_DEV = process.env.NODE_ENV !== 'production';
const path = require('path'); // eslint-disable-line
const srcPath = path.resolve('./src');
module.exports = (config) => {
const { module, resolve } = config;
const updatedConfig = {
...config,
module: {
...module,
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
}, {
test: /\.css/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader'],
}),
},
{
test: /\.mp3$/,
exclude: /node_modules/,
loader: 'file-loader',
query: {
// CSS图片目录
name: IS_DEV ? '[path][name].[ext]' : 'assets/mp3/[hash].[ext]',
}
},
{
test: /\.mp4/,
exclude: /node_modules/,
loader: 'file-loader',
query: {
// CSS图片目录
name: IS_DEV ? '[path][name].[ext]' : 'assets/video/[hash].[ext]',
}
}, {
test: /\.(png|jpg|gif)$/,
loader: 'url-loader',
query: {
limit: 10000,
// CSS图片目录
name: IS_DEV ? '[path][name].[ext]' : 'assets/[name].[ext]',
}
}, {
test: /\.less$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
localIdentName: '[sx][hash:base64:8]',
modules: true,
camelCase: true,
sourceMap: IS_DEV
}
}, {
loader: 'px2rem-loader',
options: {
remUnit: 75,
remPrecision: 8,
}
}, {
loader: 'less-loader',
options: {
sourceMap: IS_DEV
}
}],
}),
},
]
},
resolve: {
...resolve,
alias: {
components: srcPath + '/components',
}
}
};
updatedConfig.plugins.push(
new ExtractTextPlugin({filename: '[name].min.css', allChunks: true})
);
return updatedConfig;
};