Skip to content

Rollup as a service (with a little help from Browserify)

License

Notifications You must be signed in to change notification settings

webcomponents-dev/packd

 
 

Repository files navigation

packd

Rollup as a service (with a little help from Browserify).

This is a simple app for generating UMD bundles of npm packages, similar to browserify-cdn aka wzrd.in. I made it because wzrd.in sometimes goes offline, and I need its functionality for the Svelte REPL. Unfortunately I couldn't get browserify-cdn to run on now.sh, so I decided to roll my own.

And since I was rolling my own, it made sense to use Rollup. (Feel free to roll your eyes.) For npm packages that expose pkg.module, such as the D3 modules, this means you get smaller, more efficient bundles than with browserify-cdn. packd also gzips the files it serves, typically resulting in much smaller requests.

Since Rollup can't handle all of the CommonJS code on npm, packd will use Browserify (or a combination of Rollup and Browserify) where appropriate.

Using packd

You can try a hosted version of packd at https://bundle.run.

Bundles can be accessed like so. Bear in mind that if a bundle isn't cached, it needs to be installed and built before it can be served, which may take a little while:

/[name]

You can specify a tag (e.g. 'latest') or a version (e.g. '1.2.3'):

/[name]@latest

If you're using these URLs with <script> tags, you may need to specify the module's name (i.e. the global variable name used to access it, corresponding to moduleName in Rollup and standalone in Browserify). packd will guess based on the module ID, but you may need to control it with the name query:

/underscore?name=_

Hosting an instance

packd is a straightforward Express app — clone this repo, npm install (or yarn install), then npm start. To host on now, simply npm install -g now and run now.

Is this like unpkg.com?

No. unpkg.com is like a CDN for npm — it serves the actual files in npm packages. In a lot of cases that's perfect, but since some library authors don't include distributable bundles (tsk, tsk) it's not a general solution to the problem that packd addresses. Moreover, many npm package authors don't minify their code, whereas packd does.

It is, however, blazing fast and extremely reliable. If a distributable version of a dependency is on unpkg, you should always prefer that.

Credits

Thanks to James Halliday and Joshua Holbrook for their work on Browserify and browserify-cdn, and Zeit for making such an easy to use hosting environment.

License

MIT

About

Rollup as a service (with a little help from Browserify)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 84.8%
  • HTML 15.2%