所以我正在npm包脚本中运行任务,但是我想在npm start
中传递watch选项。
这有效:
"scripts": {
"scss": "node-sass src/style.scss dist/style.css -w"
}
这不会编译,监视或引发任何错误:
"scripts": {
"scss": "node-sass src/style.scss dist/style.css",
"start": "parallelshell \"npm run scss -- -w\""
}
没有parallelshell或没有简写都无法工作。
我认为问题是运行脚本在引号中传递了额外的参数,因此命令如下所示:
node-sass src/style.scss dist/style.css "-w"
我希望它可以在不添加任何依赖的情况下工作。我想念什么?
顺便说一句,我在Windows 10中,使用命令提示符/git bash。
最佳答案
这是我用于css构建的设置
"scripts": {
"css": "node-sass src/style.scss -o dist",
"css:watch": "npm run css && node-sass src/style.scss -wo dist"
},
"devDependencies": {
"node-sass": "^3.4.2"
}
-o标志设置目录以输出css。
我有一个非监视版本“css”,因为监视版本“css:watch”〜不会在运行时立即构建〜,它只能在更改时运行,所以我称之为
npm run css
致电之前
node-sass src/style.scss -wo dist
如果您只希望它在更改时运行,而不是在首次运行时运行,请使用
"css:watch": "node-sass src/style.scss -wo dist"
关于node.js - 在npm run-script中使用node-sass watch选项,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34797140/