/
webpack.config.js
44 lines (39 loc) · 1.18 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
const merge = require('webpack-merge');
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const commonConfig = require('./webpack.common.config.js');
const publicConfig = {
devtool: 'cheap-module-source-map',
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ["css-loader?modules&localIdentName=[local]-[hash:base64:5]"]
})
}
]
},
plugins: [
// 每次打包前自动清理下dist文件。
new CleanWebpackPlugin(['build/*.*']),
// 压缩生成的文件。
new UglifyJSPlugin(),
// 我们可以使用 webpack 内置的 DefinePlugin 为所有的依赖定义这个变量:
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
'HOST': '""'
}
}),
// 单独生成css文件。
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true
})
]
};
module.exports = merge(commonConfig, publicConfig);