Reputation: 12913
I am unsure if there is a setting in rails 4.2 that changed from 4.1, or if I am just crazy sauce. But this is my application.js file:
// 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_tree .
//= require bootstrap
//= require react
//= require react_ujs
//= require backbone
//= require app
//= require app/helpers/core.js
//= require app/collections/aisis_writer_user
//= require app/routers/aisis_writer_panel
//= require app/views/aisis_writer_panel
It clearly states exactly how my assets should be loaded. The are a couple of these file that have there own require statements at the top. Now in development mode, from how I see things is I do not get a giant concatenated file of assets, instead each asset is loaded as a script tag in the header of the page. That would be fine if it followed the order I have set out.
<script src="/assets/jquery.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/jquery_ujs.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/turbolinks.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app/helpers/intervals.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app/helpers/reset_intervals.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app/routers/aisis_writer_panel.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app/collections/aisis_writer_user.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app/helpers/core.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app/views/aisis_writer_panel.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/app/helpers/polling.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/bootstrap.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/react.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/react_ujs.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/backbone.js?body=1" data-turbolinks-track="true"></script>
<script src="/assets/application.js?body=1" data-turbolinks-track="true"></script>
This isn't how I specified things to be ordered at all, as a result I am getting:
uncaught ReferenceError: App is not defined
aisis_writer_user.js:1 Uncaught ReferenceError: Backbone is not defined
aisis_writer_panel.js:1 Uncaught ReferenceError: Backbone is not defined
backbone.js:219 Uncaught TypeError: Cannot read property 'each' of undefined
The way I ordered things, these errors should not - or at least not all of them - be appearing.
So my question is: Why is the asset pipeline ignoring me when I tell it to load files in a specific way?
Upvotes: 0
Views: 141
Reputation: 239491
Why is the asset pipeline ignoring me when I tell it to load files in a specific way?
It's not, it's doing exactly what you've asked it to. You are ignoring the big require_tree .
in the middle of your require
statements.
The whole point of require_tree .
is that it recursively includes all the files it finds in the directory you give it. You're giving it .
, so that that point you're going to be dumping every single .js
or .coffee
file in your app/assets/javascripts
directory into your manifest, in whatever order they happen to be read from disk.
If you didn't want that behavior, you need to remove that line.
Upvotes: 1