我尝试使用具有以下目录配置的npm脚本来编译SASS。
project
├ page1
│ └ style
│ ├ sass
│ │ └ *.scss
│ └ css
├ page2
│ └ style
│ ├ sass
│ │ └ *.scss
│ └ css
├ ...
├ pageN
│ └ style
│ ├ sass
│ │ └ *.scss
│ └ css
└ package.json
所以我考虑使用glob和node-sass的--output
选项。
{
"name": "sass",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"sass": "node-sass ./**/style/sass/ --output ./**/style/css/"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"node-sass": "^4.14.0"
}
}
但是这并没有在CSS目录中生成CSS文件。
相反,SASS目录中有一个CSS文件。这意味着将忽略用于指定输出目录的--output
选项。
如何使用npm脚本将它们编译到css目录中?
$ npm run sass
> [email protected] sass C:\Users\sanriot\Desktop\project
> node-sass ./**/assets/sass/ --output ./**/assets/css/
Rendering Complete, saving .css file...
Wrote CSS to C:\Users\sanriot\Desktop\project\page1\style\sass\style.css
Rendering Complete, saving .css file...
Wrote CSS to C:\Users\sanriot\Desktop\project\page2\style\sass\style.css
Rendering Complete, saving .css file...
Wrote CSS to C:\Users\sanriot\Desktop\project\page3\style\sass\style.css
Wrote 3 CSS files to C:\Users\sanriot\Desktop\project\**\style\css\
node-sass [options] <input> [output]
之前进行。