[英]NPM Scripts Post Hook not Firing
I am testing using npm scripts to eventually remove my reliance on Gulp. 我正在使用npm脚本进行测试,以最终消除对Gulp的依赖。 I am starting simply with one main custom script called
watch
. 我仅从一个名为
watch
主要自定义脚本开始。 This script will ultimately run all scripts prefaced with the watch
name; 该脚本最终将运行以
watch
名称开头的所有脚本; for example watch:styles
. 例如
watch:styles
。 My watch:styles
script will use node-sass to compile my sass files down into CSS. 我的
watch:styles
脚本将使用node-sass将我的sass文件编译成CSS。 This works. 这可行。 However, my next step is creating a
postwatch:styles
script that runs the newly created .css
files through PostCSS and Autoprefixer. 但是,我的下一步是创建一个
postwatch:styles
脚本,该脚本通过PostCSS和Autoprefixer运行新创建的.css
文件。
The Problem , though, is my postwatch:styles
hook is never triggered to run. 问题是我的
postwatch:styles
挂钩从未触发运行。
package.json 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"
]
}
Any advice or suggestions as to why my post hook isn't firing? 关于为何我的帖子挂钩无法触发的任何建议或建议? The initial
watch:styles
runs just fine. 最初的
watch:styles
运行得很好。 If I run yarn postwatch:styles
manually the script runs correctly. 如果我手动运行
yarn postwatch:styles
,脚本将正确运行。 Could there be a silent error on my watch:styles
that is preventing the hook from firing? 我的
watch:styles
上是否可能出现无声错误,导致钩子无法触发?
Any advice will be greatly appreciated. 任何建议将不胜感激。
Since watch:styles
calls node-sass
in watch mode, the command never returns but remains in an active state waiting for your files to change. 由于
watch:styles
在监视模式下调用node-sass
,因此该命令从不返回,而是保持活动状态,等待文件更改。
And since there is no positive return, postwatch:styles
will never be called. 而且由于没有正收益,
postwatch:styles
永远不会调用postwatch:styles
。
You should try another approach maybe watching your files with watch
or nodemon
. 您应该尝试另一种方法,也许使用
watch
或nodemon
监视文件 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.