-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.cfg.dev.js
89 lines (86 loc) · 2.02 KB
/
webpack.cfg.dev.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
const path = require("path");
const dir = path.join.bind(path, __dirname);
const webpack = require("webpack");
const HappyPack = require("happypack");
const FriendlyErrorsPlugin = require("friendly-errors-webpack-plugin");
const devConfig = {
devtool: "cheap-eval-source-map",
// devtool: "cheap-module-eval-source-map",
output: {
/*这里本来应该是[chunkhash]的,但是由于[chunkhash]和webpack-dev-server --hot不兼容。只能妥协*/
filename: "js/[name].[hash:5].js",
},
module: {
rules: [
{
test: /_\.css$/i,
use: "happypack/loader?cacheDirectory=true&id=cssm",
},
{
test: /[^_]\.css$/i,
use: "happypack/loader?cacheDirectory=true&id=css",
},
{
test: /\.less$/i,
use: "happypack/loader?cacheDirectory=true&id=less",
},
],
},
plugins: [
new webpack.DefinePlugin({
"process.env": { "NODE_ENV": JSON.stringify("development") },
}),
new HappyPack({
id: "cssm",
threads: 4,
loaders: [
"style-loader",
"css-loader?modules&localIdentName=[name]_[local]_[hash:base64:5]",
],
}),
new HappyPack({
id: "css",
threads: 4,
loaders: ["style-loader", "css-loader", "postcss-loader"],
}),
new HappyPack({
id: "less",
threads: 4,
loaders: ["style-loader", "css-loader", "postcss-loader", "less-loader"],
}),
new FriendlyErrorsPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.HotModuleReplacementPlugin(),
],
devServer: {
contentBase: dir("dist"),
historyApiFallback: true,
compress: true,
hotOnly: true,
inline: false, // ie11以下不支持inline
noInfo: true,
https: false,
quiet: false,
open: false,
hot: true,
clientLogLevel: "error",
publicPath: "/",
host: "0.0.0.0",
port: 8888,
proxy: {
"/proxy/abc": {
target: "http://abc.com",
secure: false,
changeOrigin: true,
},
"/proxy/xyz": {
target: "https://xyz.com",
secure: true,
changeOrigin: true,
pathRewrite: { "^/proxy/xyz": "/abc" },
},
},
},
};
module.exports = devConfig;