选择Webpack打开哪个浏览器?

时间:2017-07-05 08:48:59

标签: webpack html-webpack-plugin

我使用找到的here

的CLI安装了Vue.js.
var utils = require('./utils')
var webpack = require('webpack')
var config = require('../config')
var merge = require('webpack-merge')
var baseWebpackConfig = require('./webpack.base.conf')
var HtmlWebpackPlugin = require('html-webpack-plugin')
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')

// add hot-reload related code to entry chunks
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
  baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
})

module.exports = merge(baseWebpackConfig, {
  module: {
    rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
  },
  // cheap-module-eval-source-map is faster for development
  devtool: '#source-map',
  plugins: [
    new webpack.DefinePlugin({
      'process.env': config.dev.env
    }),
    // https://github.com/glenjamin/webpack-hot-middleware#installation--usage
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    // https://github.com/ampedandwired/html-webpack-plugin
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: 'index.html',
      inject: true
    }),
    new FriendlyErrorsPlugin()
  ]
})

当我运行它时,打开我的默认浏览器Safari。我想在不更改操作系统默认浏览器的情况下指定Chrome(仅用于开发)。

webpack.dev.conf.js如下:

lua_pop(L, 1)

有人知道如何在此配置中指定Chrome?

1 个答案:

答案 0 :(得分:3)

在github上已经为它分配了一个问题,但它仍处于开发阶段。

Issue Link

<强>更新

这个问题最终被合并了。现在,您可以使用CLI或webpack.dev.conf指定浏览器。

  1. 使用CLI "start": "webpack-dev-server --config webpack.dev.js --open chrome"

  2. 使用webpack.config.js:

    module.exports = {
      //...
      devServer: {
        open: 'Google Chrome'
      }
    };
    

    Documentation Link