Webpack launch browser automatically

前端 未结 9 941
遥遥无期
遥遥无期 2021-02-03 17:18

Gulp + live reload serves up my content on localhost and (here\'s what I\'m after) launches the browser automatically at the server url whenever i run the gulp

相关标签:
9条回答
  • 2021-02-03 18:13

    To launch the browser, one can add --open to CLI command as the accepted answer points it out

    npm start --open
    

    or

    ng serve --open
    

    To avoid doing it all the time: there is a simple change to make in package.json

    "scripts": {
        "ng": "ng",
        "start": "ng serve --open",
        ...
      },
    
    0 讨论(0)
  • 2021-02-03 18:16
    directory/folder: package.json
    
    {
      "devDependencies": {
      "babel-core": "^6.26.3",
      "babel-loader": "^7.1.5",
      "babel-preset-es2015": "^6.24.1",
      "babel-preset-react": "^6.24.1",
      "webpack": "^4.16.0",
      "webpack-dev-server": "^3.1.4"
    },
      "name": "",
      "version": "1.0.0",
      "main": "index.js",
      "license": "MIT",
      "description": "",
      "author": "",
      "private": false,
      "scripts": {
        "start": "webpack-dev-server --open --watch"
     },
      "dependencies": {
        "webpack-cli": "^3.0.8"
      }
    }
    

    This start script will run the dev server, and both automatically open and update (on-save) the web page. This is for WebPack 4.

    0 讨论(0)
  • 2021-02-03 18:16

    Launch browser automatically and it is also possible to specify a page when opening the browser with webpack 4.

    "scripts": {
       ...
       "start": "webpack-dev-server --open-page index2.html"
    }
    
    0 讨论(0)
提交回复
热议问题