grass: rust 编写的一个 sass 编译工具

使用 rust 编写的一个 sass 工具
更新于: 2025-11-06 21:50:32

背景

  • 一些项目,安装 sass 慢,而且重复安装麻烦
  • 而且,各种版本,经常变化 sass:math 等语法经常报 warning
  • dart-sass 小版本也是 warning
  • 期望:寻找一个2进制的 golang/rust 生态的 sass 工具

安装

cargo install grass

$ grass --version
grass 0.13.4

常用配置

$ grass --help
A Sass compiler written purely in Rust

Usage: grass [OPTIONS] [INPUT] [OUTPUT]

Arguments:
  [INPUT]   Sass files
  [OUTPUT]  Output CSS file

Options:
  -v, --version                
      --stdin                  Read the stylesheet from stdin
  -I, --load-path <LOAD_PATH>  A path to use when resolving imports. May be passed multiple times.
  -s, --style <STYLE>          Minified or expanded output [default: expanded] [possible values: expanded, compressed]
      --no-charset             Don't emit a @charset or BOM for CSS with non-ASCII characters.
      --no-unicode             Whether to use Unicode characters for messages.
  -q, --quiet                  Don't print warnings.
  -h, --help                   Print help
配置使用
压缩
$ grass input.scss > output.css -s compressed
node_modules 里的 import
--load-path
--quiet
不显示 warning

效果展示

源码转化后
body {
  font-size: 16px;
  .btn{
    min-width: 100px;
    user-select: none;
  }
}
body{font-size:16px}body .btn{min-width:100px;user-select:none}