簡體   English   中英

是否可以使用Compass in rails為開發和生產設置不同的SASS輸出樣式?

[英]Is it possible to set different SASS output style for development and production with Compass in rails?

假設我想為開發設置嵌套樣式並為生產壓縮。 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

除了Voldy的回答之外,我通過創建一個名為sass_config的初始化程序並將其放入其中來解決了這個問題:

Sass::Plugin.options[:style] = case RAILS_ENV
  when 'production' then :compressed
  when 'staging' then :compact
  when 'development' then :expanded
  else
    :nested
end

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM