在 npm run-script 中使用 node-sass watch 选项 [英] Using node-sass watch option with npm run-script

查看:45
本文介绍了在 npm run-script 中使用 node-sass watch 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在 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""
}

在没有 parallelshell 或没有速记的情况下不起作用.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆