开启express服务器,本地调试线上数据。
- 需要静态资源设置contentBase,可设置多个目录
- 当访问的html不为index.html,可以设置index参数
- proxy设置代理的资源
module.exports = {
...
devServer: {
contentBase: [publicPath, path.join(__dirname, '../../'), path.join(__dirname, '../../../')],
port: 8083,
host: 'vip.xxx.com.cn',
open: true,
openPage: 'index.php?r=check/bbb&path=aaa',
overlay: true,
index: 'client.html',
proxy: {
'/index*': {
target: 'http://xxx.com.cn/',
bypass: function (req, res, proxyOptions){
//req.headers.accept.indexOf('html') !== -1
if (req.url.indexOf('r=check/bbb') !== -1) {
console.log('Skipping proxy for browser request.');
return '/client.html';
}
},
historyApiFallback: true,
changeOrigin: true,
//secure: false
},
}
},
}
package.json
"server": "NODE_ENV=development webpack-dev-server --config config/webpack.server.js --colors --hot",