我想动态地预编译一些scss文件(在运行时)。在Rails 3中,我曾经使用过Sprockets :: StaticCompiler。
env = Rails.application.assets
target = File.join(Rails.public_path, config.assets.prefix)
compiler = Sprockets::StaticCompiler.new(env,
target,
config.assets.precompile,
:manifest_path => config.assets.manifest,
:digest => config.assets.digest,
:manifest => digest.nil?)
compiler.compile
我应该如何在Rails 4中执行此操作?互联网上没有任何文档或任何内容。
感谢您的帮助
答案 0 :(得分:1)
我遇到了同样的问题并通过使用Sass引擎编译我的资产然后将其写入public / assets文件夹来解决它。
asset = env.find_asset(self.sass_file_path)
compressed_body = ::Sass::Engine.new(asset.body, {
:syntax => :scss,
:cache => false,
:read_cache => false,
:style => :compressed
}).render
File.open(File.join(Rails.root, "public", "assets", self.stylesheet_file(asset.digest)), 'w') { |f| f.write(compressed_body) }