7 Star 0 Fork 0

willem.wang / react-demo-web

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
server.js 1.55 KB
一键复制 编辑 原始数据 按行查看 历史
willem.wang 提交于 2018-10-31 11:46 . 22
/**
* 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);
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/tianjishuju_willem.wang/react.git
git@gitee.com:tianjishuju_willem.wang/react.git
tianjishuju_willem.wang
react
react-demo-web
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891