node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »

cjs-transform

Transform Require.js modules to use simplified CommonJS wrapper

I prefer to use the simplified CommonJS wrapper when using Require.js.

This module transforms the following:

define([
       'test',
       './relative/folder/test',
       'module/here', 'on/same/line',
       'noVar'
], function(test, relativeFolder, someModule, sameLine) {
 
    test.doSomething();
 
    relativeFolder();
 
});

into:

define(function(require) {
 
    var test = require('test');
    var relativeFolder = require('./relative/folder/test');
    var someModule = require('module/here');
    var sameLine = require('on/same/line');
    require('noVar');
 
    test.doSomething();
 
    relativeFolder();
 
});

API

var cjsTransform = require('cjs-transform');
 
var isTransformed = cjsTransform(from[, to]);
 
// if `to` is not specified, it changes `from` 
// there is no async version