在npm run-script中使用node-sass watch选项 [英] Using node-sass watch option with npm run-script
问题描述
所以我正在npm程序包脚本中运行任务,但是我想通过npm start
中的watch选项.
So I'm running tasks in npm package scripts but I want to pass the watch option in npm start
.
这有效:
"scripts": {
"scss": "node-sass src/style.scss dist/style.css -w"
}
这不会编译,监视或引发任何错误:
This doesn't compile, watch, or throw any error:
"scripts": {
"scss": "node-sass src/style.scss dist/style.css",
"start": "parallelshell \"npm run scss -- -w\""
}
没有并行shell或没有简写都无法工作.
Doesn't work without parallelshell either or without shorthand.
我认为问题是运行脚本在引号中传递了额外的参数,因此命令如下所示:
I assume the problem is the run-script is passing the extra argument in quotes, so the command comes out like:
node-sass src/style.scss dist/style.css "-w"
我希望此方法无需添加任何依赖即可工作.我想念什么?
I'd like this to work without adding any dependencies. What am I missing?
顺便说一句,我在Windows 10中,使用命令提示符/git bash.
Btw, I'm in Windows 10 with command prompt/git bash.
推荐答案
这是我用于CSS构建的设置
This is my setup for css building
"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"〜不会在运行后立即构建〜,它只能在更改时运行,所以我叫
The -o flag sets the directory to output the css. I have a non-watching version "css" because the watching version "css:watch" ~doesn't build as soon as it's run~, it only runs on change, so I call
npm run css
致电
node-sass src/style.scss -wo dist
如果您只希望它在更改时运行,而不是在首次运行时运行,请使用
If you only want it to run on change, and not when first run, just use
"css:watch": "node-sass src/style.scss -wo dist"
这篇关于在npm run-script中使用node-sass watch选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!