我是 npm newbee,正在尝试使用纯 npm(没有 grunt、gulp 等)进行非常简单的构建过程。我所有的包 json 脚本都可以正常工作,但负责监视 SCSS 文件并在文件更改时运行编译器的脚本除外。
这是我的 Package.json 文件,它应该是 self 解释的:
{
"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"
}
}
有问题的脚本是“watch:css”。
当我更改我的“index.html”时,它会相应地更改网页,但是当我更改我的任何 SCSS 文件时没有任何更改效果。
最佳答案
你在 Windows 上吗? 如果是这样,请尝试将单引号替换为转义双引号,如 onchange README 中所述。
"watch:css": "onchange \"src/scss/*.scss\" -- npm run build:scss",
关于node.js - npm 插件 "onchange"无法识别 scss 文件更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37261016/