bundle loader for webpack
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 34 commits ahead, 20 commits behind webpack-contrib:master.
Latest commit d9e48e5 Nov 3, 2016
Failed to load latest commit information.
.gitignore use query arguments Nov 2, 2012
LICENSE.md Add LICENSE file Sep 18, 2015
README.md Update README Nov 3, 2016
index.js Add promises support Nov 3, 2016
package.json Ver. 2.1.0 Nov 3, 2016
patch.js v2.0 May 24, 2016
plugin.js Implement plugin for exporting installedChunks callbacks Aug 25, 2015


async-module-loader for webpack

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

npm install async-module-loader


webpack documentation: Using loaders

Also you will need to use 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) {
}, 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) {
}, function onError() {
  // error happened

Specifying a chunk name

require('async-module-loader?name=my-chunk!./file.js')(function onLoad(mod) {
}, 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();
  }, 500);
}, function onError() {
  // error happened


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


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