1

我将webpack4 升级到 5。在 package.json 我有:

开始": "webpack-dev-server --config config/webpack.js --mode development --cssExtract --uiTest --progress --color --port 2000 --open"

升级后我得到:

[webpack-cli] 错误:未知选项“--cssExtract”

--cssExtract是自定义标志。我在配置文件中使用它:

    cssExtract
      ? new MiniCssExtractPlugin({
          filename: '[contenthash].css',
        })
      : false,
4

1 回答 1

0

webpack 5 中的替代方法是使用 env vars https://webpack.js.org/guides/environment-variables/

网络包 4

包.json

{
  "scripts": {
    "build": "npm-run-all --serial build-light build-dark",
    "build-light": "webpack --color-mode light",
    "build-dark": "webpack --color-mode dark"
  }
}

webpack.config.js

module.exports = (env, options) => {
  // console.log(options.colorMode)

网络包 5

包.json

{
  "scripts": {
    "build": "npm-run-all --serial build-light build-dark",
    "build-light": "webpack --env color-mode=light",
    "build-dark": "webpack --env color-mode=dark"
  }
}

webpack.config.js

module.exports = (env, options) => {
  // console.log(env['color-mode'])
于 2021-11-23T15:17:53.577 回答