代码之家  ›  专栏  ›  技术社区  ›  Voldy

有没有可能设置不同的SASS输出风格,以开发和生产的指南针在轨道?

  •  7
  • Voldy  · 技术社区  · 16 年前

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

    output_style = :compact # or :nested, :expanded, :compressed
    
    2 回复  |  直到 15 年前
        1
  •  7
  •   Voldy    16 年前

    看起来很简单:

    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
    
        2
  •  6
  •   Dominik Grabiec    15 年前

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