Convert normal js to cmd module.


Convert normal js to CMD module.(What is CMD module? 中文定义)

It is a experimental project, being cautious to use it in important situation please!

$ npm install cmdize -g

There is a js file exmple.js: = "abc";

Cmdize it!

$ cmdize example.js
Reading /Users/afc163/Desktop/example.js ...
No found any global variables.
cmdized.js is generated.
  >> /Users/afc163/Projects/cmdize/cmdized.js

Then the cmdized.js would be generated:

define(function(requireexportsmodule) { = "abc";
  • clearGlobal
$ cmdize example.js --clear-global

It will remove abc from window safely.

define(function(require, exports, module) { = "abc";
try { delete } catch(e) { = null }
var cmdize = require('cmdize');
cmdize(code, options, function(result) {
  // print cmdized code