NPM 脚本 Post 挂钩未触发

NPM Scripts Post Hook not Firing

我正在使用 npm 脚本进行测试,以最终消除对 Gulp 的依赖。我只是从一个名为 watch 的主要自定义脚本开始。此脚本最终将 运行 所有以 watch 名称开头的脚本;例如 watch:styles。我的 watch:styles 脚本将使用 node-sass 将我的 sass 文件编译成 CSS。这行得通。但是,我的下一步是创建一个 postwatch:styles 脚本,该脚本 运行 通过 PostCSS 和 Autoprefixer 运行 新创建的 .css 文件。

问题,但是,我的 postwatch:styles 挂钩从未触发到 运行。

package.json

{
  "name": "npm-scripts-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "watch": "npm-run-all --parallel watch:*",
    "watch:styles": "node-sass -w ./src/styles/main.scss ./dist/assets/styles/app.css",
    "postwatch:styles": "postcss -u autoprefixer --no-map ./dist/assets/styles/app.css -o ./dist/assets/styles/app.css"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {},
  "dependencies": {
    "autoprefixer": "^7.1.1",
    "node-sass": "^4.5.3",
    "postcss-cli": "^4.0.0",
    "yarn-run-all": "^3.1.1"
  },
  "browserslist": [
    "last 3 versions"
  ]
}

关于为什么我的 post 钩子没有触发的任何意见或建议?最初的 watch:styles 运行 很好。如果我 运行 yarn postwatch:styles 手动脚本 运行 正确。我的 watch:styles 上是否存在阻止挂钩触发的静默错误?

任何建议将不胜感激。

由于 watch:styles 在监视模式下调用 node-sass,该命令永远不会 return 秒,而是保持活动状态等待您的文件更改。

而且由于没有正数return,postwatch:styles永远不会被调用。

您应该尝试另一种方法,也许 watching your files with watchnodemon