npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-library-umd

v1.0.1

Published

Gulp plugin for transforming node modules into various flavors of UMD (Universal Module Definition) by wrapping files in umd templates.

Downloads

6

Readme

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

gulpfile.js

var gulp = require('gulp');
var gulpSourceMaps = require('gulp-sourcemaps'); // optional
var gulpData = require('gulp-data'); // optional
var gulpLibraryUmd = require('gulp-library-umd')

gulp.task('build', function () {
  return gulp.src('source.js')
    // optional per-file settings
    .pipe(gulpData(function (file) {
      return {};
    }))
    // optional source map support
    .pipe(gulpSourceMaps.init())
    // ...
    .pipe(gulpLibraryUmd({
      templateName: 'umd',
      require: {
        libA: 'libA',
        libB: {
          name: 'lib-b-default',
          amd: 'lib-b-amd',
          cjs: 'lib-b-cjs',
          node: 'lib-b-node',
          web: 'libBWeb'
        }
      },
      exports: 'result',
      namespace: 'myModuleGlobal'
    }))
    .pipe(gulpSourceMaps.write())
    .pipe(gulp.dest('dist'))
});

input: source.js

var result = {
  A: libA,
  B: libB,
  B: libC
};

result: dist/source.umd.js

(function (root, factory) {
  if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    
    define(["libA","lib-b-amd"], factory);
  } else if (typeof module === 'object' && module.exports) {
    // Node. Does not work with strict CommonJS, but
    // only CommonJS-like environments that support module.exports,
    // like Node.
    
    module.exports = factory(require("libA"), require("lib-b-node"));
  } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
    // CommonJs
    
    (function (results) {
      
      for (var key in results) {
        if ({}.hasOwnProperty.call(results, key))
          exports[key] = results[key];
      }
      
    })(factory(require("libA"), require("lib-b-cjs")));
  } else {
   // Browser globals
   
   root.myModuleGlobal = factory(root.libA, root.libBWeb);
  }
}(this, function (libA,libB) {
  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

gulpLibraryUmd({ })

Identical libraries for each mode

gulpLibraryUmd({ 
  requires: { 
    libA: 'library-a', 
    libB: 'library-b' 
  } 
}) 

Different libraries for each mode

gulpLibraryUmd({ 
  requires: { 
    libA: {
      name: 'library-a', // used as default name when no alternative is specified for the mode
      web : 'libraryA',  // web globals should be valid identifiers 
      amd : null         // AMD does not require this library
    }
  } 
})

Installation

npm install --save-dev gulp-library-data