Skip to content

Requiring a sprockets-preprocessed file #29

@gabrielecirulli

Description

@gabrielecirulli

I'm trying to get sprockets to preprocess a file that contains a directive so that when I require() using browserify, it will contain the generated JavaScript.

This is my setup (within app/assets/javascripts):

system/
  rails_routes.js
application.js

application.js is the main file, and it starts the rest of the application. I would like to be able to do something like

var rr = require("./system/rails_routes.js");

in it.

In system/react_routes.js, I have the following:

//= require js-routes

console.log("Does this work?");

As an aside, I also 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.

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions