Webpack 自动启动浏览器 [英] Webpack launch browser automatically

查看:36
本文介绍了Webpack 自动启动浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Gulp + live reload 在本地主机上提供我的内容并且(这就是我想要的)每当我运行 gulp 命令(即我没有单击浏览器图标并手动导航到网址).这也可以在 Webpack 中完成吗?

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 command (i.e I don't have to click the browser icon and navigate to the url manually). Can this be done in Webpack too?

我尝试了一个名为 open-browser-webpack-plugin 的插件,但我无法让它工作.

I've tried a plugin called open-browser-webpack-plugin, but I could not get it to work.

推荐答案

对于 webpack 2.x 版,您只需将 --open open 添加到 CLI,如下所述:

For webpack version 2.x, you just add --open open to the CLI as documented here:

https://webpack.js.org/configuration/dev-server/#devserver-open

或者,将以下配置添加到您的 webpack.config.js:

Alternatively, add the following config to your webpack.config.js:

devServer: {
  open: true
}

这篇关于Webpack 自动启动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆