webpack - 选择打开哪个Webpack浏览器?

标签 webpack html-webpack-plugin

我使用找到的here使用CLI安装了Vue.js:

# 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吗?

最佳答案

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

Issue Link

更新

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

  • 使用CLI "start": "webpack-dev-server --config webpack.dev.js --open chrome"
  • 使用webpack.config.js:
    module.exports = {
      //...
      devServer: {
        open: 'Google Chrome'
      }
    };
    

    Documentation Link
  • 关于webpack - 选择打开哪个Webpack浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44921308/

    相关文章:

    javascript - 错误 : while using devtool ="source-map" option in webpack config version 5

    typescript - 在 TypeScript 和 Next.js 中使用绝对导入解析模块

    javascript - 自定义build设置所需的 webpack vue.js 热重载配置

    javascript - 如何从 html-webpack-plugin 生成的 index.html 中排除 bundle.css?

    javascript - 我将 webpack v4 升级到 v5,之后出现 "cannot add property"错误

    javascript - HTML webpack 插件不解析 EJS 变量

    javascript - 从 npm 包导入 ES6 模块

    javascript - 使用 webpack 创建串联的 .d.ts