有一些webpack开发服务器配置(它是整个配置的一部分):
config.devServer = {
contentBase: './' + (options.publicFolder ? options.publicFolder : 'public'),
stats: {
modules: false,
cached: false,
colors: true,
chunk: false
},
proxy: [{
path: /^\/api\/(.*)/,
target: options.proxyApiTarget,
rewrite: rewriteUrl('/$1'),
changeOrigin: true
}]
};
function rewriteUrl(replacePath) {
return function (req, opt) { // gets called with request and proxy object
var queryIndex = req.url.indexOf('?');
var query = queryIndex >= 0 ? req.url.substr(queryIndex) : "";
req.url = req.path.replace(opt.path, replacePath) + query;
console.log("rewriting ", req.originalUrl, req.url);
};
}
我使用以下命令执行webpack:
node node_modules/webpack-dev-server/bin/webpack-dev-server.js --host 0.0.0.0 --history-api-fallback --debug --inline --progress --config config/webpack.app.dev.js
我可以使用http://localhost:8080
本地计算机访问开发服务器,但我也想通过移动平板电脑(它们位于同一Wi-Fi网络中)访问服务器。
如何启用它?谢谢!
webpack-dev-server --host=0.0.0.0 --disable-host-check --useLocalIp
见github.com/webpack/webpack-dev-server/issues/882