使用 Node-sass 缩小 CSS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40579330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Minify CSS with Node-sass
提问by Matt Leach
I'm using SCSS in my NodeJS project and have my script working to turn all my seperate SCSS files into a single CSS file using the following command
我在我的 NodeJS 项目中使用 SCSS,并让我的脚本使用以下命令将所有单独的 SCSS 文件转换为单个 CSS 文件
node-sass -w public/css/scss/style.scss public/css/style.css
My only issue is that I also want the CSS file to be minified. Is this possible with Node-sass? The docs say there is an option for 'compact' but it doesn't seem to work when I try
我唯一的问题是我还希望缩小 CSS 文件。这可以用 Node-sass 实现吗?文档说有一个“紧凑”选项,但是当我尝试时它似乎不起作用
node-sass -w compact public/css/scss/style.scss public/css/style.css
Thank you in advance for any help.
预先感谢您的任何帮助。
回答by vretamal
In the node-sass documentationsays you have to use
--output-style
, and it could be nested | expanded | compact | compressed
. To minify use compressed
在node-sass 文档中说你必须使用
--output-style
,它可能是nested | expanded | compact | compressed
. 最小化使用compressed
For example:
例如:
node-sass -w public/css/scss/style.scss public/css/style.css --output-style compressed
will minify the CSS.
将缩小 CSS。
回答by TidyDev
node-sass supports outputting minified CSS with the --output-style
parameter.
node-sass 支持使用--output-style
参数输出缩小的 CSS 。
outputStyle
输出样式
- Type: String
- Default:
nested
- Values:
nested
,expanded
,compact
,compressed
- 类型:字符串
- 默认:
nested
- 值:
nested
,expanded
,compact
,compressed
After installing the node-sass npm package. I added the build-css
line to my package.json file.
安装 node-sass npm 包后。build-css
我将这一行添加到我的 package.json 文件中。
"scripts": {
"build-css": "node-sass --include-path scss scss/main.scss public/css/main.css --output-style compressed",
},
Then I simply need to type npm run build-css for the content inside my /scss/main.scss file to be transformed into compressed (minified) css inside the /public/css/main.min.css
然后我只需要键入 npm run build-css 将我的 /scss/main.scss 文件中的内容转换为 /public/css/main.min.css 中的压缩(缩小)css
More information can be found within the node-sass Github repo's documentation here https://github.com/sass/node-sass#outputstyle
更多信息可以在 node-sass Github repo 的文档中找到https://github.com/sass/node-sass#outputstyle
回答by Omar Vega
"scss": "node-sass --watch scss -o app/css"
This work for me
"scss": "node-sass --watch scss -o app/css"
这对我有用