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

browserify-async-define

v2.1.6

Published

Browserify plugin for async-define

Downloads

3

Readme

Note: This is working and battle tested, but I suggest to use either webpack or rollup instead (I explain the reason at the bottom)

browserify-async-define

This browserify plugin can be used to wrap some dependencies using async-define and thus, factor out those in common bundles.

Options:

  • -d --dependsOn "name:label[:filename]" the dependency "name" will come from a different bundle with the label "label". If you add "filename" (optional) this dependency will be bundled in that file.
  • -e --exports "file:label" the module.exports of this file will be exposed with the label "label"
  • --verbose it will output which modules was removed and which stays. Useful to detect if a module is in because of a dependency of a dependency
  • --collapse the requires ids are transformed in numbers instead of strings (more compact bundles)

With the main.js:

var $ = require('jquery');
var $node = $('<div>Hello</div>').appendTo(document.body);

You can build bundle and main like this:

browserify main.js -o dist/main.js -p [browserify-async-define -d jquery:jquery2.2:dist/common.js]

or using the api:

var browserifyAsyncDefine = require('browserify-async-define');
var b = browserify('main.js')
  .plugin(browserifyAsyncDefine, {
    dependsOn: ['jquery:jquery2.2:dist/common.js]
  });

and then load them like this:

<script async src="dist/common.js"></script>
<script async src="dist/main.js"></script>

You can factor out multiple dependencies and use the "label" to express different versions:

browserify main.js -o dist/main.js -p [browserify-async-define -d jquery:jquery20:dist/jquery.js -d react:react014:dist/react.js -d react-dom:reactDom014:dist/react.js]

and then load them like this:

<script async src="dist/jquery.js"></script>
<script async src="dist/react.js"></script>
<script async src="dist/main.js"></script>

async-define will isolate the namespace and allow to use different versions of a package.

peerDependencies

To use this plugin you should also install this package:

"async-define": "latest",

Why avoiding this

async-define has the same interface used by AMD modules. So it was very easy to create a rollup or webpack plugin because they are already able to produce an AMD output of the bundle. This plugin instead is pretty complicated and heavy to maintain. I consider this to be deprecated and only apply the least possible maintenance.