Backbone.js, Underscore.js, and Sprockets 1.0.x Concatenation
If so, then we've got a lot in common, friend! Particularly if you happen to run into this error:
1`block in interpolate_constants!': couldn't find constant `([\s\S]+?)' in line 756 of ~/d/js/lib/underscore-1.1.7.js (Sprockets::UndefinedConstantError)
Fortunately for us, we aren't the first ones to run into this problem. It was
filed as ticket 23
on the prototype library lighthouse page. Even better,
github community member
matehat solved this by adding an
:interpolate_constants option to the
Sprockets::Secretary constructor in
smile-inducing commit d73565.
Now, if we have even more in common, you've never built a gem from source either. Let's walk through this together!
gem uninstall sprockets
git clone https://github.com/matehat/sprockets.git
gem build sprockets.gemspec
gem install sprockets-1.0.2.gem
And just like that, we can pass a new option into our
constructor to actually create one file, frameworks and all.
1secretary = Sprockets::Secretary.new(2 :root => '.',3 :asset_root => 'bin',4 :load_path => ['../lib'],5 :source_files => ['src/*.js', 'src/**/*.js']6)7secretary.concatenation.save_to('bin/app.js')
1secretary = Sprockets::Secretary.new(2 :root => '.',3 :asset_root => 'bin',4 :load_path => ['../lib'],5 :source_files => ['src/*.js', 'src/**/*.js'],6 :interpolate_constants => false )7secretary.concatenation.save_to('bin/app.js')