transform AMD or CommonJS inspired by require.js to CommonJS.
before(AMD):
define(['dep1', 'dep2'], function(dep1, dep2OtherName) {
return dep1 + dep2OtherName;
});
transform after(CommonJS):
var dep1 = require('dep1');
var dep2OtherName = require('dep2');
module.exports = dep1 + dep2OtherName;
- transform
define(['dep1', 'dep2'], function() {});
torequire('dep1');require('dep2');
- transform
define(function(){return statements;})
tomodule.exports = statements;
- transform
require('obj/xxx')
torequire('../obj/xxx')
So, Notice this tool can not transform all require.js features.
First, install amd2cmd:
npm install -g amd2cmd
Second, cd your project, and exec cmd:
amd2cmd --in=src/scripts/**/*.js --out=build/scripts --baseDir=src/scripts
First, install amd2cmd:
npm install --save amd2cmd
Then, you can use amd2cmd like this:
import transform from 'amd2cmd';
transform(['src/scripts/**/*.js'], 'build/scripts', 'src/scripts')
.on('finish', function() {
console.log('finish to transform amd code to cmd code');
});
Build the project shell:
$ npm build
Test the project shell:
$ npm test
Test the project with coverage result:
$ npm coverage
Generate JavaScript API doc:
$ npm esdoc