Conditional require in Sprockets

不打扰是莪最后的温柔 提交于 2019-12-04 13:43:24

Perhaps, since your example uses debug as a parameter, you could use settle for having the asset in the development environment?

If so, in config/environments/development.rb

config.assets.precompile << 'lib-debug.js'

A possible solution is to add the following into the bundle_app method:

env.context_class.class_eval "def debug; #{!!debug}; end"

The updated bundle_app() method:

def bundle_app(debug)
  env = Sprockets::Environment.new
  env.append_path "app/"
  env.context_class.class_eval "def debug; #{!!debug}; end"
  env.js_compressor = Uglifier.new
  assets = env.find_asset("app.js.erb")
  return assets.to_s
end
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!