npm插件"onchange"无法识别scss文件的更改

Hom*_*mam 2 onchange build-tools node.js npm

我是npm newbee并尝试使用纯粹的npm进行非常简单的构建过程(没有grunt,gulp等).我的所有包json脚本都可以正常工作,负责监视SCSS文件并在文件更改时运行编译器.
这是我的Package.json文件,应该是自我解释:

    {
      "name": "test-site.com",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "scss": "node-sass --indent-type tab --indent-width 1 --output-style expanded -o dist/css src/scss",
        "autoprefixer": "postcss -u autoprefixer -r dist/css/app.css",
        "build:css": "npm run scss && npm run autoprefixer",
        "serve": "browser-sync start --server --files 'dist/css/*.css, **/*.html, !node_modules/**/*.html'",
        "reload": "browser-sync reload",
        "watch:css": "onchange 'src/scss/*.scss' -- npm run build:scss",
        "build:all": "npm run build:css",
        "watch:all": "npm-run-all -p serve watch:css",
        "postinstall": "npm run build:all && npm run watch:all"
      },
      "author": "Homam",
      "license": "ISC",
      "devDependencies": {
        "autoprefixer": "latest",
        "browser-sync": "latest",
        "node-sass": "latest",
        "npm-run-all": "latest",
        "onchange": "latest",
        "postcss-cli": "latest"
      }
    }
Run Code Online (Sandbox Code Playgroud)

有问题的脚本是"watch:css".
当我更改我的"index.html"时,它会相应地更改网页,但是当我更改任何我的SCSS文件时没有任何更改效果.

小智 11

你在Windows上吗?如果是这样,请尝试用onchange README中所述的转义双引号替换单引号.

"watch:css": "onchange \"src/scss/*.scss\" -- npm run build:scss",
Run Code Online (Sandbox Code Playgroud)


小智 5

可能是因为

"watch:css": "onchange 'src/scss/*.scss' -- npm run build:scss",
Run Code Online (Sandbox Code Playgroud)

引用未定义的build:scss吗?您已经定义了“ scss”和“ build:css”。尝试:

"watch:css": "onchange 'src/scss/*.scss' -- npm run build:css",
Run Code Online (Sandbox Code Playgroud)