node package manager

require2commonjs

require2commonjs

NPM version Build Status Dependency Status

This tool helps you convert your js module from AMD to CommonJS form, which could be used in commonjs system like nodejs, cortex, spm

Especially when you manage your js files via requirejs, you can pass config in requirejs like root, baseUrl, paths as options, to make =r2cjs= handle your relative dependencies correctly.

Code like following:

define([
  'backbone',
  'zepto',
  'view/layout'
], function(Backbone, $, Layout) {
  var App = {};
 
  $.extend(App, Backbone.Events);
 
  App.layout = new Layout();
 
  return App;
})

will be transformed to:

var Layout = require('./view/layout');
var Backbone = require('backbone');
var $ = zepto;
 
var App = {};
 
$.extend(App, Backbone.Events);
 
App.layout = new Layout();
 
module.exports = App;

Installation

$ npm install require2commonjs --save

Usage

r2cjs --root . --baseUrl app base.js

Convert one file

r2cjs rq.js >  common.js
 
# or
 
r2cjs rq.js -o common.js

Convert multiple files

r2cjs --dest ../common base.js app.js layout.js

APIs

var r2c = require('require2commonjs');
 
r2c(file, {
  root:root, 
  baseUrl: baseUrl, 
  paths: paths
});
 

Licence

MIT