NPM脚本Post Hook不会触发
问题描述:
我正在测试使用npm脚本来最终消除我对Gulp的依赖。我开始使用一个名为watch
的主要自定义脚本。该脚本最终将运行以watch
名称开头的所有脚本;例如watch:styles
。我的watch:styles
脚本将使用node-sass将我的sass文件编译成CSS。这工作。但是,我的下一步是创建一个postwatch:styles
脚本,该脚本通过PostCSS和Autoprefixer运行新创建的.css
文件。NPM脚本Post Hook不会触发
问题,虽然,是我的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
上是否有无声错误,可以防止吊钩发射?
任何意见将不胜感激。
答
由于watch:styles
在手表模式下调用node-sass
,该命令永不返回,但仍处于活动状态,等待文件更改。
由于没有正面回报,所以postwatch:styles
将永远不会被调用。
您应该尝试另一种方法,可能是watching your files with watch
或nodemon
。
这很有道理。谢谢! – Yuschick