How to open browser to localhost through npm scripts

后端 未结 4 1300
眼角桃花
眼角桃花 2020-12-28 15:38

I\'ve been trying to figure out how to write a npm script that will culminate with the application being launched in the user\'s browser without them having to

4条回答
  •  死守一世寂寞
    2020-12-28 15:58

    For Webpack users: OpenBrowserPlugin does the trick too!

    Install one dependency:

    npm install open-browser-webpack-plugin --save-dev
    

    And add this in webpack config file:

    var OpenBrowserPlugin = require('open-browser-webpack-plugin');
    
    ...
    
    plugins: [
      new OpenBrowserPlugin({ url: 'http://localhost:3000' })
    ]
    

    Update (may 2019)

    Please note OpenBrowserPlugin is abandoned and a severe vulnerability hasn't been fixed for a while. However rodrigopandini has forked it here. Use npm install rodrigopandini/open-browser-webpack-plugin to use it.

提交回复
热议问题