如何让 webpack 开发服务器在端口 80 和 0.0.0.0 上运行以使其可公开访问? [英] How to make the webpack dev server run on port 80 and on 0.0.0.0 to make it publicly accessible?
问题描述
我是整个 nodejs/reactjs 世界的新手,如果我的问题听起来很傻,我深表歉意.所以我在玩 reactabular.js.
I am new to the whole nodejs/reactjs world so apologies if my question sounds silly. So I am playing around with reactabular.js.
每当我执行 npm start
时,它总是在 localhost:8080
上运行.
Whenever I do a npm start
it always runs on localhost:8080
.
如何将其更改为在 0.0.0.0:8080
上运行以使其可公开访问?我一直在尝试阅读上述 repo 中的源代码,但未能找到执行此设置的文件.
How do I change it to run on 0.0.0.0:8080
to make it publicly accessible? I have been trying to read the source code in the above repo but failed to find the file which does this setting.
另外,补充一点 - 如果可能的话,我如何让它在端口 80
上运行?
Also, to add to that - how do I make it run on port 80
if that is at all possible?
推荐答案
这样的事情对我有用.我猜这应该对你有用.
Something like this worked for me. I am guessing this should work for you.
使用这个运行 webpack-dev
Run webpack-dev using this
webpack-dev-server --host 0.0.0.0 --port 80
并在 webpack.config.js 中设置
And set this in webpack.config.js
entry: [
'webpack-dev-server/client?http://0.0.0.0:80',
config.paths.demo
]
注意如果您使用的是热加载,则必须这样做.
Note If you are using hot loading, you will have to do this.
使用这个运行 webpack-dev
Run webpack-dev using this
webpack-dev-server --host 0.0.0.0 --port 80
并在 webpack.config.js 中设置
And set this in webpack.config.js
entry: [
'webpack-dev-server/client?http://0.0.0.0:80',
'webpack/hot/only-dev-server',
config.paths.demo
],
....
plugins:[new webpack.HotModuleReplacementPlugin()]
这篇关于如何让 webpack 开发服务器在端口 80 和 0.0.0.0 上运行以使其可公开访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!