假设我想为开发设置嵌套样式并为生产进行压缩。 Compass 配置文件中只有一个选项:
output_style = :compact # or :nested, :expanded, :compressed
最佳答案
看起来这很容易:
output_style = RAILS_ENV == "production" ? :compressed : :nested
为了检查它,我在不同的环境中运行了这个 rake 任务(我必须在运行这个任务之前更改 sass 源):
namespace :sass do
desc 'Updates stylesheets if necessary from their Sass templates.'
task :update => :environment do
Sass::Plugin.update_stylesheets
end
end
您可以将此任务放在 lib/tasks/sass.rake 中。
否则,我在 Capistrano deploy.rb 中运行此任务以在部署期间自动更新生产中的样式表:
after 'deploy:restart', 'sass:update'
namespace :sass do
desc 'Updates the stylesheets generated by Sass'
task :update, :roles => :app do
invoke_command "cd #{current_release}; rake sass:update RAILS_ENV=production"
end
end
关于ruby-on-rails - 是否可以在 Rails 中使用 Compass 为开发和生产设置不同的 SASS 输出样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2386014/