I'm using browserify-rails and I'm trying to get sprockets to preprocess a file that contains a sprockets directive, so that when I require()
it using browserify, it will contain the generated JavaScript.
The sprockets directive tries to include the output of the gem js-routes, in order to allow me to access the Rails routes from the clientside.
This is my setup (within app/assets/javascripts
):
system/
rails_routes.js
application.js
application.js
is the main file, and it runs the rest of the application. I would like to be able to do something like
var rr = require("./system/rails_routes.js");
in it, and get access to the routes object.
Within system/react_routes.js
, I have the following:
//= require js-routes
console.log("Does this work?");
(as an aside, I configured js-routes
to place the output in an object called module.exports
, so to comply with the CommonJS model, as described in railsware/js-routes#121)
The only issue is that when I look at the generated bundle, the sprockets directive is still there and has not been expanded.
The console.log
call is also there and gets executed when I require()
the module.
Is there a way to get this to work? What is the correct way to have sprockets preprocess a file before bundling it with browserify-rails?