如何使用 Compass 生成 css 的单个缩小文件?

How to generate single minify file of css using Compass?

我想将我的 sass 文件编译成项目中的单个 minify css。

使用 Sass

缩小

在命令行中,输入以下内容:

$ sass --watch style.scss:style.css --style compressed

用罗盘缩小

首先,通过在命令行中输入以下内容,确保您已在 Compass 中设置项目:

$ compass create path/to/your_project

之后,您会注意到Compass在您的项目目录中创建了两个文件夹; /sass/ 和 /stylesheets/。它还创建了一个 config.rb 文件。

打开 config.rb 文件,您应该会看到类似于以下内容的内容:

# Require any additional compass plugins here.

# Set this to the root of your project when deployed:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"

# You can select your preferred output style here (can be overridden via the command line):
output_style = :compressed # :expanded or :nested or :compact or :compressed

# To enable relative paths to assets via compass helper functions. Uncomment:
# relative_assets = true

# To disable debugging comments that display the original location of your selectors. Uncomment:
line_comments = false


# If you prefer the indented syntax, you might want to regenerate this
# project again passing --syntax sass, or you can uncomment this:
# preferred_syntax = :sass
# and then run:
# sass-convert -R --from scss --to sass sass scss && rm -rf sass && mv scss sass

在您的 config.rb 文件中,第 11 行可能会被 # 符号注释掉。取消注释 output_style 行,使其看起来像上面的示例。

最后,您需要让 Compass 开始监视您的 scss 文件的更改。在命令行输入:

$ cd /path/to/your_project
$ compass watch

完成!


Credits