代码拉取完成,页面将自动刷新
/**
* Created by chencheng on 16-11-17.
*/
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./build/webpack.config');
const tool = require('./scripts/tool');
// const host = tool.getLocalIP() || '0.0.0.0';
const host = 'localhost';
const port = 8099; // 端口号
const mockHost = 'http://localhost:3000'; // mock服务主机+端口
// webpack 自动重新加载,采用inline
config.entry.app.push('webpack-dev-server/client?http://' + host + ':' + port + '/');
// 启动服务
const server = new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
// 指定服务器内容指定目录
contentBase: config.output.path,
watchContentBase: true,
// 对于某些系统,监听大量文件系统会导致大量的 CPU 或内存占用,这个选项可以排除一些巨大的文件夹
watchOptions: {
ignored: /node_modules/
},
// 开启服务器的模块热替换(HMR)
hot: false,
// 当请求不存在的路由时,直接返回首页
historyApiFallback: {
index: '/public/',
disableDotRule: true,
},
stats: {
colors: true,
},
proxy: {
'/mockAPI/*': {
target: mockHost,
changeOrigin: true,
secure: false
},
'/apexAPI': {
target: 'http://10.0.3.179:9090',
pathRewrite: { '^/apexAPI': '' }
}
}
});
// 将其他路由,全部返回index.html
server.app.get('*', (req, res) => {
res.sendFile(`${__dirname}/public/index.html`);
});
console.log('http://' + host + ':' + port);
server.listen(port, host);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。