ruby-on-railsrubygemsasset-pipeline

Rails: Add assets to manifest from within gem


Is there a way to add assets (JS) to the manifest from within a gem with explicitly referencing them in the manifest file?

The assets are in the correct place and picked–up just fine, but I'd like to get around asking the user to manually add e.g.

//= require 'my_asset_path'

to their manifest file.

I'd also like to avoid the approach describe here since it seems a bit brittle: http://bibwild.wordpress.com/2011/09/20/design-for-including-rails-engine-assets-into-pipeline-manifest/


Solution

  • Because Sprockets is designed to (primarily) be a compile time operation for production, the only approach available is writing your asset path to the manifest via a generator.

    As you've noted this IS going to be brittle because you cannot guess where the plugin should go relative to other require directives in the javascript manifest. And you would have to assume the application manifest is being used, when quite a number of people use a secondary manifest for admin.

    Providing good documentation about where to add the plugin and possible interactions may be the best approach.