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

esbuild-plugin-umd-wrapper

v3.0.0

Published

UMD wrapper for esbuild

Downloads

15,212

Readme

Description

An esbuild plugin to wrap your js into UMD format.

Installation

yarn add -D esbuild-plugin-umd-wrapper
# or
npm install -D esbuild-plugin-umd-wrapper

Usage

const esbuild = require("esbuild");
const { umdWrapper } = require("esbuild-plugin-umd-wrapper");

esbuild
  .build({
    entryPoints: ["src/input.js"],
    outdir: "dist",
    bundle: true,
    format: "umd", // or "cjs"
    plugins: [umdWrapper()],
  })
  .then((result) => console.log(result))
  .catch(() => process.exit(1));

Customize the wrapper.

See all options.

esbuild.build({
  entryPoints: ["src/input.js"],
  outdir: "dist",
  bundle: true,
  format: "umd", // or "cjs"
  plugins: [umdWrapper({ libraryName: "myLibrary" })],
});

Wrapper options will be applied for all entryPoints.


Notes

The plugin will be triggered only if esbuild format is set to "cjs" or "umd".
Before esbuild execution the plugin will set that option to "cjs".

Known Issues

Internally the wrapper plugin uses esbuild's banner and footer options to create UMD.
In consequence running multiple esbuild builds concurrently reusing the same Build option object references MAY produce unexpected build output Ex:

const options = {
  entryPoints: ["src/input.js"],
  outdir: "dist",
  bundle: true,
  format: "umd",
  plugins: [umdWrapper({ libraryName: "myLibrary" })],
};

// ❌ avoid this
await Promise.all([esbuild.build(options), esbuild.build({ ...options, minify: true, outdir: "dist/min" })]);
// ❌ avoid this
esbuild.build(options);
esbuild.build({ ...options, minify: true, outdir: "dist/min" });
// ✅ Its better
await esbuild.build(options);
await esbuild.build({ ...options, minify: true, outdir: "dist/min" });

When I use export default myFunc, resulting output is not directly callable!
Instead it's an object {__esModule: true, default: myFunc}

This is not a bug, and it's not related to umd-wrapper-plugin.
This is how esbuild transpiles export default to CJS.

As a workaround use exports = myFunc.


Examples

If you are not familiar with UMD, see usage examples in test directory.