Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails asset pipeline: how to create custom manifest file

I am trying to make a custom manifest javascript file seperate from application.js. I've take the code from application.js and pasted it into a new file I've called "other_manifest.js" and placed in the assets/javascrips directory. Here is the code:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .

In my assets.rb file, I've included the line:

Rails.application.config.assets.precompile += %w(other_manifest.js)

I precompile and clean the assets locally, and then when I run the page, all i get is the exact text from the manifest file. It is not bringing in any of the files. How do I create a custom manifest file?

like image 516
Philip7899 Avatar asked May 01 '15 15:05

Philip7899


1 Answers

Easily

You have application.js. Create a second file: other_manifest.js

Then in your layout layouts/application.html.erb (could be a different layout altogether):

<% if condition %>
  <%= javascript_include_tag 'other_manifest' %>
<% else %>
  <%= javascript_include_tag 'application' %>
<% end %>

And yes, you need to add in your config/initializers/assets.rb (followed by reboot):

Rails.application.config.assets.precompile += %w(other_manifest.js)

Also, make sure to remove the //= require_tree . from manifests. Because it will include ALL the javascript in the manifest (making having a different manifest pointless)

like image 186
Ruslan Avatar answered Nov 10 '22 13:11

Ruslan