-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.cfg.js
51 lines (49 loc) · 1.47 KB
/
webpack.cfg.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
const webpack = require("webpack");
const UglifyJSPlugin = require("uglifyjs-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const lessLoader = new ExtractTextPlugin(
"css/[name].[contenthash:5].css",
{ allChunks: true }
);
const publicConfig = {
devtool: false,
// devtool: "source-map",
module: {
loaders: [
{
test: /_\.css$/i,
loader: ExtractTextPlugin.extract("style-loader", "css-loader?modules&localIdentName=[hash:base64:8]", "postcss-loader"),
},
{
test: /[^_]\.css$/i,
loader: ExtractTextPlugin.extract("style-loader", "css-loader", "postcss-loader"),
},
{
test: /\.less$/i,
loader: lessLoader.extract(["css", "postcss", "less"]),
// 这里不需要 style-loader, 加了反而报错
// less在生产环境的编译配置很特殊 https://github.com/webpack-contrib/extract-text-webpack-plugin/blob/webpack-1/README.md
},
],
},
plugins: [
new CleanWebpackPlugin(["dist"]),
new webpack.DefinePlugin({
"process.env": { "NODE_ENV": JSON.stringify("production") },
}),
// new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.OccurrenceOrderPlugin(),
// new webpack.HashedModuleIdsPlugin(),
new UglifyJSPlugin({
sourceMap: false,
uglifyOptions: { ie8: true },
}),
new ExtractTextPlugin(
"css/[name].[contenthash:5].css",
{ allChunks: true }
),
lessLoader,
],
};
module.exports = publicConfig;