browserify-rails
- Manage JS modules with
npm
- Serve assets with Sprockets
- Require modules with
require()
(without separate//= require
directives) - Only build required modules
Getting Started
Add this line to your application's Gemfile:
gem 'browserify-rails'
Create package.json
in your Rails root:
{
"name": "something",
"devDependencies" : {
"browserify": "2.13.x"
},
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
}
[TODO: Write a Rails generator for this]
Then run:
npm install
Then start writing CommonJS, and everything will magically work!:
// foo.js
module.exports = function (n) { return n * 11 }
// application.js
var $ = require('./foo');
console.log(foo(12));
Contributing
Pull requests appreciated.