How to get access to webpack-dev-server from devices in local network?

后端 未结 5 507
北海茫月
北海茫月 2020-12-04 06:05

There is some webpack dev server config (it\'s part of the whole config):

config.devServer = {
  contentBase: \'./\' + (options.publicFolder ? options.public         


        
5条回答
  •  无人及你
    2020-12-04 06:16

    I could not comment in order to add additional information to forresto's answer, but here in the future (2019) you'll need to add a --public flag due to a security vulnerability with --host 0.0.0.0 alone. Check out this comment for more details.

    In order to avoid "responding to other answers" as an answer here's forresto's advice plus the additional details you'll need to make this work:

    Add both:

    --host 0.0.0.0

    and

    --public :

    where your-host is the hostname (for me it is (name)s-macbook-pro.local)) and port is whatever port you're trying to access (again, for me it's 8081).

    So here's what my package.json looks like:

      "scripts": {
        ...
        "start:webpack": "node_modules/.bin/webpack-dev-server --host 0.0.0.0 --public s-macbook-pro.local:8081",
        ...
      },
    
    

提交回复
热议问题