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

youemdee

v1.0.1

Published

Wrap a browserify/browser-pack JavaScript bundle in a Universal Module Definition (UMD) with optional external dependencies, while preserving source maps

Downloads

772

Readme

youemdee Build Status

Wrap a browserify/browser-pack JavaScript bundle in a Universal Module Definition (UMD) with optional external dependencies, while preserving source maps.

Example

Plug this into your build chain just as you would with any other transform-stream:

browserify src/main.js | youemdee MyModule --dependency dep1

Or if you're using the Node API:

browserify('./src/main.js')
  .bundle()
  .pipe(youemdee.createTransform('MyModule', dependencies))
  .pipe(process.stdout)

Usage

youemdee

  Reads a browserify/browser-pack JavaScript bundle from stdin and wraps it in a Universal Module Definition (UMD) with optional external dependencies. An optional source map can be provided inline in the input, and will be updated and output inline with the UMD bundle on stdout.

Synopsis

  $ youemdee <module-name>

  It is highly encouraged to stick to [a-zA-Z] for module-name, as anything else will make accessing your module in the global scope more difficult (window.MyModule vs. window['my-module']).

Options

  -h, --help         Display this usage guide
  -d, --dependency   A dependency in the form of name[:global[:amd]], multiple occurrences allowed

Examples

  No external dependencies               $ youemdee MyModule < bundle.js
  React and ReactDOM as external deps.   $ youemdee MyComponent --dependency react:React --dependency react-dom:ReactDOM < bundle.js

API

const youemdee = require('youemdee')

youemdee(source:String, moduleName:String, dependencies:Array): String

Will wrap source in a UMD. If there is an inline source map found in source it will be extracted, updated to reflect the changes made, then reattached inline to the returned string.

moduleName is the namespace which the module will have when attached to the global scope, e.g. window.MyModule. It is highly encouraged to stick to [a-zA-Z] so as not to make accessing your module unnecessarily difficult.

The optional dependencies is an array. Each entry can either be a string or a dependency spec of the following form:

{
  name: String, // The internal and external CJS name
  amd: String, // Dep. name as defined in the AMD loader
  global: String, // Dep. name in the global scope
}

When specified as a string the value will be used for internal, external, amd, and global dependency names.

youemdee.createTransform(moduleName:String, dependencies:Array): Transform

Just like youemdee(), but instead of expecting source as an argument it returns a transform stream which reads until end, wraps in a UMD, and emits the updated bundle. Very useful in a stream-style build pipeline.

Why?

browserify's --standalone works well as long as you don't have any external dependencies. umd itself (which browserify uses indirectly via browser-pack) doesn't yet support external dependencies.

Future

This tool targets browserify (or more specifically: browser-pack) bundles. It will, in theory, also work for other JavaScript bundlers that create a similar pseudo-require output. PRs to add support for other types of input are more than welcome.

Compatibility

Node >=6. This is only due to the level of syntactic sugar used. Writing the code down to support older versions of node won't be too much work, if the demand is there to support it.

License

ISC