第 1 步: 开发配置 config.rb 应如下所示:
# Basic configuration.
http_path = "/"
css_dir = "css"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "js"
# You can select your preferred output style here (can be overridden via the command line).
# Options: ":expanded", ":nested", ":compact", ":compressed"
output_style = :expanded
# Enable debugging comments that display the original location of your selectors.
line_comments = true
# Re-compile the sass files using the minified configuration.
on_stylesheet_saved do
`compass compile -c config_minified.rb --force`
end
第 2 步:您必须添加另一个配置文件 config_minified.rb,它应该如下所示:
# Basic configuration.
http_path = "/"
css_dir = "css/minified"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "js"
# Compressed the output for production.
output_style = :compressed
# Disable debugging comments for production.
line_comments = false
第 3 步:照常编译,您就可以开始了:
compass watch
/css/minified/style.css 将自动生成。
按照这些步骤操作后,项目应如下所示:
/css
/css/style.css
/css/minified/style.css
/images
/sass
/sass/style.scss
config.rb
config_minified.rb
编辑
如果您不想弄乱每个项目的相对路径,您可以更改 config_minified.rb 以使用相对于根文件夹的 css 文件夹。
# do not use the css_dir = "css/minified" because it will break the images.
css_dir = "css-minified"