Search code examples
javascriptruby-on-railswebpackactiveadminruby-on-rails-5.1

Can ActiveAdmin load javascript bundled by webpack? - Rails 5.1


I've upgraded from rails 4.2.6 to rails 5.1, and then started to use webpack.
All set up for using webpack have done, but I can't figure out how to load javascript files on the ActiveAdmin page.
ActiveAdmin loads app/assets/javascripts/active_admin.js.coffee by default.
Is there a way to load javascript files which is bundled by webpack on the ActiveAdmin page?


Solution

  • Webpack is not yet officially supported. The approach we are using for now is to monkey patch ActiveAdmin::Views::Header to include tags to load the generated output of Webpack, eg.

    class ActiveAdmin::Views::Header < Component
      def build(namespace, menu)
        ...
        render "application/custom_header_tags"
      end
    end
    

    In our case our custom_header_tags.erb uses React On Rails but substitute whatever integration you prefer.