eduardolundgren / gulp-umd

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

Adding window, document to IIFE but not not require it for commonJS, use root & root.document instead #25

Open alvarotrigo opened 6 years ago

alvarotrigo commented 6 years ago

I would like to include window and document for minification purposes. As having them in the IIFE will reduce a bit the size of the minified file.

I would like to get something like this:

(function(global, factory) {
    'use strict';
    if (typeof define === 'function' && define.amd) {
        define(['jquery'], function($) {
          return factory($, global, global.document, global.Math);
        });
    } else if (typeof exports === "object" && exports) {
        module.exports = factory(require('jquery'), global, global.document, global.Math);
    } else {
        factory(jQuery, global, global.document, global.Math);
    }
})(typeof window !== 'undefined' ? window : this, function($, window, document, Math, undefined) {

But adding as a dependencies window and document and up creating for commonJS the following:

 module.exports = factory(require('jQuery'), require('root'), require('document'));

Which i believe is not correct and should be instead:

module.exports = factory(require('jquery'), global, global.document);