选择Webpack打开哪个浏览器?

问题描述 投票:3回答:1

我使用CLI安装了Vue.js,如here

# install vue-cli
$ npm install --global vue-cli
# create a new project using the "webpack" template
$ vue init webpack my-project
# install dependencies and go!
$ cd my-project
$ npm install
$ npm run dev

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

webpack.dev.conf.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()
  ]
})

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

webpack html-webpack-plugin
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.