-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathwebpack.dev.js
More file actions
executable file
·77 lines (71 loc) · 1.94 KB
/
webpack.dev.js
File metadata and controls
executable file
·77 lines (71 loc) · 1.94 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
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
/**
* @file 开发配置
* @author atom-yang
*/
/* eslint-env node */
const merge = require("webpack-merge");
const path = require("path");
const http = require("http");
const https = require("https");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const minimist = require("minimist");
const { isObject } = require("lodash");
const mockMapper = require("./mock.json");
const { OUTPUT_PATH } = require("./util");
const proxy = require("./proxy.json");
const baseConfig = require("./webpack.base");
const defaultTargetOptions = {
// dev-mode, 开发方式,local - 本地mock开发,test - 联调开发
string: ["dev-mode"],
default: {
"dev-mode": "test",
},
};
const args = minimist(process.argv.slice(2), defaultTargetOptions);
const devMode = args["dev-mode"];
const proxyServer =
devMode === "local"
? {}
: proxy.map((v) => {
const agent = v.target.match("https")
? https.globalAgent
: http.globalAgent;
console.log("v.target.match('https')", !!v.target.match("https"), v);
return {
context: v.context,
target: v.target,
changeOrigin: true,
secure: false,
proxyTimeout: 8000,
agent: agent,
pathRewrite: v.pathRewrite,
onProxyReq(proxyReq) {
const { headers } = v;
Object.keys(headers).forEach((v) => {
proxyReq.setHeader(v, headers[v]);
});
},
};
});
const devConfig = {
mode: "development",
devtool: "cheap-module-source-map",
output: {
filename: "[name].js",
},
plugins: [new MiniCssExtractPlugin()],
devServer: {
// disableHostCheck: true,
// webpack5 require
static: OUTPUT_PATH,
host: "0.0.0.0",
port: 3000,
compress: true,
hot: true,
// hotOnly: true,
// inline: false,
historyApiFallback: true,
proxy: proxyServer,
},
};
module.exports = merge(baseConfig, devConfig);