Rails 5 “gemify” assets manifest file

谁都会走 提交于 2019-12-11 01:44:41

问题


Update

Got this in a working state. Gem can be found here: https://github.com/jakehockey10/popcircle

Original post:

I am trying to "gemify" a jquery plugin as a learning experience. The plugin I'm using also depends on jquery.easing, so in the gem's vendor/assets/javascripts folder, I have both jquery.easing.js as well as the other jquery plugin.

Here is what my gem's <name_of_gem>.rb file looks like:

require '<name_of_gem>/version'

module <NameOfGem>
  class Engine < ::Rails::Engine
    class Engine < ::Rails::Engine
      initializer '<name_of_gem>.assets.precompile' do |app|
        app.config.assets.precompile += %w(
          big_round.png
          one.png
          two.png
          three.png
          four.png
          five.png
        )
      end
  end
end

Here is the current structure of the gem:

.
├── bin
│   ├── console
│   └── setup
├── CODE_OF_CONDUCT.md
├── Gemfile
├── Gemfile.lock
├── lib
│   ├── <name_of_gem>
│   │   └── version.rb
│   └── <name_of_gem>.rb
├── LICENSE.txt
├── name_of_gem.gemspec
├── Rakefile
├── README.md
├── test
│   ├── <name_of_gem>_test.rb
│   └── test_helper.rb
└── vendor
└── assets
└── javascripts
├── jquery.easing.js
└── jquery.<name-of-gem>.js

When using the gem in a test app, I'd like to be able to just require the gem like //= require <name-of-gem> and have that be sufficient to have both of the javascripts files in the gem's vendor folder to be loaded into the test app's asset pipeline. However, instead, I have to //= require jquery.easing and the other file individually in my test app.

Is there a way to have my gem bundle those assets up together and not have the developer of the app have to require both files individually?

Instead of this in my test app's application.js:

//= require jquery-easing.js
//= require jquery.<name-of-plugin>.js

I'd like to give the developers the opportunity to just say this in application.js:

//= require <name_of_gem>

来源:https://stackoverflow.com/questions/38537357/rails-5-gemify-assets-manifest-file

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