将Sprockets的`depend_on`指令指向非资产文件 [英] Point Sprockets' `depend_on` directive to a non-assets file

查看:90
本文介绍了将Sprockets的`depend_on`指令指向非资产文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个app/assets/javascripts/moufa.js.erb文件,其中填充了config/moufa.yml文件中的值.我想使用depend_on sprockets指令,以便每次更改yaml文件时,它都会重新编译js文件.

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.

推荐答案

我们能够通过添加新指令来解决此问题.该指令(将其放在config/initializers/sprockets.rb中)在config/目录中添加了对文件的依赖:

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

这篇关于将Sprockets的`depend_on`指令指向非资产文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆