forked from hypeserver/react-date-range
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
42 lines (39 loc) · 1.37 KB
/
server.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
var path = require('path');
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.dev.config');
var opn = require('opn');
var ip = '0.0.0.0';
var port = 9031;
if (typeof config.entry === 'string') {
config.entry = ["webpack-dev-server/client?http://"+ip+":"+port, "webpack/hot/dev-server" ,config.entry];
}else if(typeof config.entry === 'object'){
for(var k in config.entry){
if( k !== 'commons'){
var main = config.entry[k]
config.entry[k] = ["webpack-dev-server/client?http://"+ip+":"+port, "webpack/hot/dev-server"].concat(main)
}
}
}
new WebpackDevServer(webpack(config), {
contentBase: path.resolve(__dirname, './'),
host : ip,
hot: true,
disableHostCheck : true,
//设置webpack-dev-server启动的时候,bundles的输出的路径,打包的时候这个publicPath没有作用
publicPath: config.output.publicPath,
// /api/* 会指向 http://127.0.0.1:3000/api/* 如 /api/users 就会指向 http://127.0.0.1:3000/api/users
proxy : {
'/api/*' : {
target : 'http://127.0.0.1:9001'
}
},
historyApiFallback: true
}).listen(port,ip, function (err) {
if (err) {
console.log(err); //eslint-disable-line no-console
}else{
opn('http://127.0.0.1:' + port);
console.log('Listening at http://127.0.0.1:' + port); //eslint-disable-line no-console
}
});