gpt4 book ai didi

javascript - NPM 脚本后 Hook 未触发

转载 作者:行者123 更新时间:2023-12-03 04:11:31 25 4
gpt4 key购买 nike

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

问题是我的 postwatch:styles 钩子(Hook)永远不会被触发运行。

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"
]
}

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

任何建议将不胜感激。

最佳答案

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

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

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

关于javascript - NPM 脚本后 Hook 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44316367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com