如何在 visual studio 构建之前 运行 多个 webpack 任务?

How to run multiple webpack task before build in visual studio?

我有多个不同 'purpose' 和之前的 webpack 文件,我需要 运行 不同的 webpack 任务,例如:

package.json:
"scripts": {
  "webpack-dll": "set NODE_ENV=dll && webpack",
  "webpack-admin": "set NODE_ENV=admin && webpack",
  "webpack-dev": "set NODE_ENV=dev && webpack"
}

在构建之前我想要 运行 'dll' 'admin' 和 'dev' 任务。但是我不能将多个任务绑定到 before build 部分。

有解决办法吗?

谢谢。

您可以在 package.json 的脚本部分创建另一个条目并调用它。

"scripts": {
  "webpack-dll": "set NODE_ENV=dll && webpack",
  "webpack-admin": "set NODE_ENV=admin && webpack",
  "webpack-dev": "set NODE_ENV=dev && webpack",
  "before-build: "npm run webpack-dll && npm run webpack-admin && npm run webpack-dev"
}

另一种选择是添加 npm-run-all 包。然后你可以 运行 像这样并行执行任务:

"scripts": {
  "webpack-dll": "set NODE_ENV=dll && webpack",
  "webpack-admin": "set NODE_ENV=admin && webpack",
  "webpack-dev": "set NODE_ENV=dev && webpack",
  "before-build: "run-p webpack-dll && npm run webpack-admin && npm run webpack-dev"
}