【问题标题】:NPM Scripts Post Hook not FiringNPM 脚本后挂钩未触发
【发布时间】:2017-11-03 02:58:00
【问题描述】:

我正在使用 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"
  ]
}

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

任何建议将不胜感激。

【问题讨论】:

    标签: javascript node.js npm postcss npm-scripts


    【解决方案1】:

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

    而且由于没有正回报,postwatch:styles 将永远不会被调用。

    您应该尝试另一种方法,可能是watching your files with watchnodemon

    【讨论】:

    • 这很有意义。谢谢!
    猜你喜欢
    • 2016-11-07
    • 1970-01-01
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 2020-05-03
    相关资源
    最近更新 更多