-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.dev.config.js
52 lines (50 loc) · 1.8 KB
/
webpack.dev.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
45
46
47
48
49
50
51
52
const webpack = require('webpack');
const HtmlwebpackPlugin = require('html-webpack-plugin');
const merge = require('webpack-merge');
const baseConfig = require('./webpack.base.config.js');
const devConfig = merge(baseConfig, {
devtool: 'eval-source-map',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"'
}),
new HtmlwebpackPlugin({
title: 'react-webpack-demo',
filename: 'index.html',
template: './template.html'
}),
// 创建一个在编译时可以配置的全局常量,在业务代码中获取
new webpack.DefinePlugin({
DEVELOPMENT: JSON.stringify(true),
PRODUCTION: JSON.stringify(false),
})
],
devServer: {
// todo: proxy选项
proxy: {
'/page*': {
target: 'http://localhost:8080',
changeOrigin: true,
secure: 'false',
bypass: function(req, res, proxyOptions) {
// do sth
// 如果浏览器请求页面返回一个html,
if (req.headers.accept.indexOf('html') !== -1) {
console.log('Skipping proxy for browser request.');
return '/index.html';
}
},
onProxyReq: function(proxyReq, req, res) {
// do sth
// 如果是post请求 而且请求体存在
// if (req.method === 'POST' && req.body) {
// const bodyData = querystring.stringify(req.body)
// proxyReq.write(bodyData)
// }
}
}
}
},
mode: 'development'
});
module.exports = devConfig;