Use twitter flight with rails
First remove the javascript_include_tag
from application.html.erb
. This will no longer be needed.
Then add a script tag for requirejs:
<script data-main="/assets/main.js" src="/assets/require/require.js"></script>
main.js
is located in app/assets/javascripts. I use bower to manage js dependencies. So my main.js
looks something like this:
require.config({
baseUrl: '/assets',
paths: {
jquery: 'jquery/jquery',
es5shim: 'es5-shim/es5-shim',
es5sham: 'es5-shim/es5-sham'
},
shim: {
'/assets/flight/lib/index': {
deps: ['jquery', 'es5shim', 'es5sham']
}
}
});
require(
[
'/assets/flight/lib/compose',
'/assets/flight/lib/registry',
'/assets/flight/lib/advice',
'/assets/flight/lib/logger',
'/assets/flight/tools/debug/debug'
],
function(compose, registry, advice, withLogging, debug){
debug.enable(true);
compose.mixin(registry, [advice.withAdvice, withLogging]);
require(['/assets/app'], function(initialize){
initialize();
});
}
);
Written by Adrian Moses
Related protips
1 Response
Please, use lib/
and vendor/
for assets that are not strictly connected with your app.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#