问题
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