gulp-library-umd
Gulp plugin for transforming node modules into various flavors of UMD (Universal Module Definition). Wraps files with a specified UMD template.
Supports gulp-sourcemaps! Supports gulp-data!
Templates
gulp-library-umd
supports many templates out of the box, including all those provided by UMDjs and gulp-umd
origin | template | amd | web | cjs | node | notes |
---|---|---|---|---|---|---|
UMDjs | amdWeb.js | X | X | Uses AMD or browser globals to create a module | ||
UMDjs | amdWebGlobal.js | X | X | Uses AMD or browser globals to create a module. Creates a web global when AMD is used | ||
UMDjs | commonjsAdapter.js | X | X | Defines a module that works in CommonJS and AMD | ||
UMDjs | commonjsStrict.js | X | X | X | Uses CommonJS, AMD or browser globals to create a module | |
UMDjs | commonjsStrictGlobal.js | X | X | X | Uses CommonJS, AMD or browser globals to create a module. Creates a web global when AMD is used | |
UMDjs | jqueryPlugin.js | X | X | X | X | Uses CommonJS, AMD or browser globals to create a jQuery plugin |
UMDjs | nodeAdapter.js | X | X | Defines a module that works in Node and AMD | ||
UMDjs | returnExports.js | X | X | X | Uses Node, AMD or browser globals to create a module. | |
UMDjs | returnExportsGlobal.js | X | X | X | Uses Node, AMD or browser globals to create a module. Creates a web global when AMD is used | |
gulp-umd | amd.js | X | ||||
gulp-umd | amdCommonWeb.js | X | X | X | ||
gulp-umd | common.js | X | ||||
gulp-umd | node.js | X | ||||
gulp-umd | web.js | X | ||||
gulp-library-umd | umd.js | X | X | X | X | Simple support for each of the major export platforms |
gulp-library-umd | umdGlobal.js | X | X | X | X | Simple support for each of the major export platforms. Creates a web global when AMD is used |
Usage
var gulp = ;var gulpSourceMaps = ; // optionalvar gulpData = ; // optionalvar gulpLibraryUmd = gulp;
input: source.js
var result = A: libA B: libB B: libC;
result: dist/source.umd.js
{ if typeof define === 'function' && defineamd // AMD. Register as an anonymous module. ; else if typeof module === 'object' && moduleexports // Node. Does not work with strict CommonJS, but // only CommonJS-like environments that support module.exports, // like Node. moduleexports = ; else if typeof exports === 'object' && typeof exportsnodeName !== 'string' // CommonJs { for var key in results if {}hasOwnProperty exportskey = resultskey; }; else // Browser globals rootmyModuleGlobal = ; }this { var result = A: libA B: libB B: libC ; return result;}; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvdXJjZS5qcyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0VBQUE7RUFDQTtFQUNBO0VBQ0E7RUFDQTtFQUNBIiwiZmlsZSI6InNvdXJjZS51bWQuanMiLCJzb3VyY2VSb290IjoiL3NvdXJjZS8iLCJzb3VyY2VzQ29udGVudCI6WyJ2YXIgcmVzdWx0ID0ge1xyXG4gIEE6IGxpYkEsXHJcbiAgQjogbGliQixcclxuICBCOiBsaWJDXHJcbn07XHJcbiJdfQ==
Options
name | type | default | description |
---|---|---|---|
templateCache |
Boolean |
true |
Cache compiled templates |
templateName |
String |
undefined |
Name of the template to use. Overrides templatePath |
templatePath |
String |
undefined |
Full file path of the template to use. Overrides template |
template |
String |
undefined |
doT.js template source to be compiled and used |
template |
Function |
undefined |
function which takes a single argument, context, and returns a string |
modes |
Array |
['cjs', 'node', 'amd', 'web'] |
List of modes to support. Used when providing distinct libraries for each mode |
indent |
Boolean |
true |
Indent content according to the specified template |
rename |
Boolean |
true |
Rename files to include the template name as an extension suffix on the basename. eg, source.js -> source.amd.js |
require |
Object |
{} |
variable name :library name id mapping of each required library |
exports |
String |
exports |
Name of the variable to export. In CommonJs, only own properties of this variable will be exported. |
exports |
Array |
List of names to exports. In most modes, these will be exported as an object literal with the given properties | |
namespace |
String |
undefined | Name to use when exporting as a global. Used in web and global modes. If no namespace is provied, one will be generated from the filename |
Specifying libraries
No libraries
Identical libraries for each mode
Different libraries for each mode
Installation
npm install --save-dev gulp-library-data