Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack inline模式用nodejs调用显示本机ip #28

Open
semi-xi opened this issue Aug 10, 2020 · 0 comments
Open

webpack inline模式用nodejs调用显示本机ip #28

semi-xi opened this issue Aug 10, 2020 · 0 comments

Comments

@semi-xi
Copy link
Owner

semi-xi commented Aug 10, 2020

网上大部分都是写的什么改

const HOST = 'x.x.x.x:8080' // 假设端口是8080

或者命令行模式增加添加参数 --host 0,0,0,0
但是大概率还是不行的。

首先在webpack dev server inline模式下,如果是命令行模式模式,是这样就可以了

webpack-dev-server --inline

这样的话加host 设置0.0.0.0是比较简单的,
但是对于nodejs调用webpack-dev-server的话则是这样的

entry: [
    'webpack-dev-server/client?http://localhost:8080',
     config.paths.demo
 ],

但是这个也只是启动localhost的
如果需要变成ip的话只需要这样就可以了

entry: [
    'webpack-dev-server/client?http://0.0.0.0:8080',
     config.paths.demo
 ]

另外还有一个技巧是打开浏览器的ip地址可以用devServer的配置useLocalIp: true

const server = new webpackDevServer(compiler, {
  hot: true, 
  quiet: true,
  historyApiFallback: true, 
  filename: config.output.filename, 
  publicPath: config.output.publicPath, 
  // host: getIPAddress(),
  stats: { 
    colors: true
  },
  open: true,
  useLocalIp: true
})
server.listen(PORT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant