有没有办法同时观察两个 Laravel Mix Webpack 配置文件的任何变化?

Is there a way to watch two Laravel Mix Webpack config files at the same time for any changes?

使用 Laravel Mix,是否可以通过一个命令查看两个 Webpack 配置文件,以便对任何基础文件的更改立即导致必要的文件被编译?

具体来说,我有以下两个与 Laravel Mix 一起使用的 Webpack 配置文件:webpack.css.mix.jswebpack.js.mix.js

然后我在 package.jsonscripts 对象中有以下命令:

"development-css": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --watch --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js --env.mixfile=webpack.css.mix",
"development-js": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --watch --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js --env.mixfile=webpack.js.mix",
"watch": "npm run development-css -- --watch & npm run development-js -- --watch",

npm run watch 命令只监视指定的第一个命令。在上述情况下,我保存到 Sass 文件的任何更改都将生成,但不会对任何 JS/Vue 文件进行更改。如果我在 watch 命令中切换两个命令,那么 JS 将基于 change/save 而不是 Sass.

有没有人知道如何构建 npm run watch 命令(或底层命令),以便我可以同时观看 Sass 和 JS?

此外,由于目前 Laravel Mix 中的错误,我不得不将 Sass 和 JS 编译分成两个单独的文件。此错误记录在此处:https://github.com/JeffreyWay/laravel-mix/issues/1914

讨论确实解决了这个错误,但没有解决如何将两个命令组合成一个监视命令。谢谢。

更新: 相关,不完全与问题相关,但与问题相关(有多个混合构建) 实际上有一个 github 项目解决了类似的问题:

https://github.com/omnichronous/multimix

不回答 afaik,同时构建两者。没试过,离开这里以防有人感兴趣

旧答案

代表@HartleySan 回答

@rmondesilva was suggesting that without concurrently one of the two commands is not working. I installed it without trying other solutions and it has worked.

npm install concurrently --save-dev

I'm using two config files (webpack.mix.js and webpack.mix.css.js), and this is the relevant part of my package.json:

"scripts": {
  "css-dev": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --env.mixfile=webpack.mix.css --config=node_modules/laravel-mix/setup/webpack.config.js",
  "js-dev": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
  "development": "concurrently \"npm run css-dev\" \"npm run js-dev\"",
  "css-watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --watch --hide-modules --env.mixfile=webpack.mix.css --config=node_modules/laravel-mix/setup/webpack.config.js",
  "js-watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --watch --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
  "watch": "concurrently \"npm run css-watch\" \"npm run js-watch\"",
  "watch-poll": "npm run watch -- --watch-poll",
  "css-production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --env.mixfile=webpack.mix.css --config=node_modules/laravel-mix/setup/webpack.config.js",
  "js-production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
  "production": "concurrently \"npm run css-production\" \"npm run js-production\"",
  "dev": "npm run development",
  "prod": "npm run production"
}

Last two ones are obviously just aliases, and I don't believe I have ever used watch-poll.

(I'm also using mergeManifest() in the two webpack.mix configuration files).

来自 https://github.com/JeffreyWay/laravel-mix/issues/1914#issuecomment-642218920