eduardolundgren / gulp-umd Goto Github PK
View Code? Open in Web Editor NEWGulp plugin for build JavaScript files as Universal Module Definition, aka UMD
License: MIT License
Gulp plugin for build JavaScript files as Universal Module Definition, aka UMD
License: MIT License
Hi,
I am using SystemJS to load my modules, this means that the wrapper sets module.exports, and then exits the conditions. That leaves the root.angularSchemaFormDynamicSelect
undefined, which causes an "Uncaught (in promise) Uncaught ReferenceError: angularSchemaFormDynamicSelect is not defined" when the wrapper tries to return it in the end, code:
;(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['angular-schema-form'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('angular-schema-form')); //Happens
} else {
root.angularSchemaFormDynamicSelect = factory(root.schemaForm); //Never happens
}
}(this, function(schemaForm) {
.........my code...............
return angularSchemaFormDynamicSelect; // This is undefined.
}));
That said, I am not sure I understand the UMD model completely..
Hi Eduardo,
Any chance of adding sourcemaps support? I've got a pending pull request which adds it if that's helpful?
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'
};
}));
Gulp has a very nice source maps plugin: gulp-sourcemaps that is very easy to support.
It would be great if gulp-umd could support it. concat-with-sourcemaps may make it even easier. I'll give it a try if I have some time today.
It doesn't seem to be require
-d outside of tests.
Perhaps you should move it to devDependencies and/or peerDependencies.
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);
this scenario doesn't work.. I have a file which exports one function as default
and one without, example:
//...some code..
export default foo
export bar
and I want to consume both at the same time, naturally, like so:
import foo, {bar} from "file.js"
Problem is, the README doesn't address this and I couldn't find any example of how the exports
setting should be written. currently it's:
exports: function(file) {
return 'foo';
}
Thanks!
Any solutions for LiveScript support? Or CoffeeScript or TypeScript?
When any source file has dash in its filename, there is a variable name that is generated with dash somewhere, so when trying to use the generated file, I get the following:
Uncaught ReferenceError: Invalid left-hand side in assignment
Would it be possible to provide an (realistic) example of how let's say angular1.x and jquery can be included as dependencies, in the string-based and object-based form?
Hi, first of all thanks for the wonderful build script!
I'm facing and issue when trying to build the module against transpiled es6 and also against es6. If that is beyond the project can you give me some suggestions? I have exhausted all my options for this. Thanks.
Overview:
gulp-umd templates is out of sync with umdjs templates.
The Problem:
As the 'global' check algorithm gulp-umd currently using in templates is deprecated, files generated gulp-umd have two serious problems:
import '/node_modules/js-untar/build/dist/untar.js';
The error looks like:
Cannot set property 'xxx' of undefined
because the outer this
, or argument root
in IIF, is undefined
see InvokIT/js-untar#30 and markedjs/marked#1292
Possible Solution:
Update the global check algorithm to umdjs's latest recommended way.
say, replace this
with typeof self !== 'undefined' ? self : this
, see returnExportsGlobal.js for example.
This is a serious problem, plz patch latest 3 versions (2.x, 1.x anf 0.2.x), also set deprecated tag on old versions at npm central registry.
As per the guidelines: https://github.com/gulpjs/gulp/blob/master/docs/writing-a-plugin/guidelines.md
In the docs it talks about being able to use returnExportsGlobal.js. but it's not included in the npm package.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.