eduardolundgren / gulp-umd

Gulp plugin for build JavaScript files as Universal Module Definition, aka UMD
MIT License
126 stars 14 forks source link

Can it add CJS like module wrapping support? #4

Closed minwe closed 7 years ago

minwe commented 9 years ago

Write module using CommonJS style:

var moduleA = require('./a');
var moduleB = require('./b');

console.log(moduleA.ver);

moduleB.someFunc();

module.exports = {
  ver: '2.0'
};

Then automatically transport dependencies from the require. Finally, wrap it to UMD:

(function(root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['require', 'exports', 'module', './a', './b'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory();
  } else {
    // I'm not sure how to do in global.
    // root.Foo = factory();
  }
}(this, function(require, exports, module) {
  var moduleA = require('./a');
  var moduleB = require('./b');

  console.log(moduleA.ver);

  moduleB.someFunc();

  module.exports = {
    ver: '2.0'
  };
}));