【问题标题】:Is it possible to set different SASS output style for development and production with Compass in rails?是否可以使用 Compass in rails 为开发和生产设置不同的 SASS 输出样式?
【发布时间】:2011-01-24 01:37:59
【问题描述】:

假设我想为开发设置嵌套样式并为生产设置压缩。 Compass 配置文件中只有一个选项:

output_style = :compact # or :nested, :expanded, :compressed

【问题讨论】:

    标签: ruby-on-rails sass compass-sass


    【解决方案1】:

    除了 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
    

    【讨论】:

      【解决方案2】:

      看起来很简单:

      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
      

      【讨论】:

        猜你喜欢
        • 2011-11-10
        • 2014-05-12
        • 2016-03-29
        • 1970-01-01
        • 1970-01-01
        • 2013-02-21
        • 2011-07-24
        • 1970-01-01
        • 2012-08-18
        相关资源
        最近更新 更多