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

async-module-loader

v2.1.0

Published

Async modules (chunks) loader for webpack with built-in error callbacks

Downloads

432

Readme

async-module-loader for webpack

Based on https://github.com/webpack/bundle-loader with improvements of error handling

npm install async-module-loader

Usage

webpack documentation: Using loaders

Also you will need to use a AsyncModulePlugin.

Basic usage

async-module-loader returns function which accepts 2 callbacks: for success and for fail Exports of the requested module are passed into success callback as a first argument

require('async-module-loader!./file.js')(function onLoad(mod) {
  mod.doSomething();
}, function onError() {
  // error happened
});

Also you can use Promises with promise option specified, like this:

require('async-module-loader?promise!./file.js').then(function onLoad(mod) {
  mod.doSomething();
}, function onError() {
  // error happened
});

Specifying a chunk name

require('async-module-loader?name=my-chunk!./file.js')(function onLoad(mod) {
  mod.doSomething();
}, function onError() {
  // error happened
});

Delayed execution

If you do not want your module to be executed immediately (maybe because some animation is in play), then you can tell to async-module-loader to load a chunk, but not execute it. In such, a function will be passed to the success callback instead of a module.exports object of requested chunk. Call that function then you will need you chunk executed:

require('async-module-loader?noexec!./file.js')(function onLoad(executeChunk) {
  setTimeout(function() {
    var mod = executeChunk();
    mod.doSomething();
  }, 500);
}, function onError() {
  // error happened
});

Plugin

To make async-module-loader work correctly you need to add AsyncModulePlugin to your plugins.

// webpack.config.js

var AsyncModulePlugin = require('async-module-loader/plugin');

module.exports = {
  // ...

  plugins: [
    // ... other plugins

    new AsyncModulePlugin()
  ]
  // ...
}

Query parameters

  • name: Use this to specify output name for requested chunk. See webpack documentation

  • promise: Use this to return a promise from async-module-loader.

  • noexec: Use this to delay chunk execution

License

MIT (http://www.opensource.org/licenses/mit-license)