Point Sprockets' `depend_on` directive to a non-assets file

拈花ヽ惹草 提交于 2019-12-07 00:50:02

问题


I have an app/assets/javascripts/moufa.js.erb file that gets populated with values from a config/moufa.yml file. I want to use the depend_on sprockets directive so that every time the yaml file gets changed, it recompiles the js file.


回答1:


We were able to solve this by adding a new directive. This directive (put this in config/initializers/sprockets.rb) adds a dependency on a file in the config/ directory:

class Sprockets::DirectiveProcessor
  def process_depend_on_config_directive(file)
    path = File.expand_path(file, "#{Rails.root}/config")
    context.depend_on(path)
  end
end


来源:https://stackoverflow.com/questions/14710569/point-sprockets-depend-on-directive-to-a-non-assets-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!