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
{ mod;} { // error happened};
Also you can use Promises with promise
option specified, like this:
;
Specifying a chunk name
{ mod;} { // 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:
{ ;} { // error happened};
Plugin
To make async-module-loader
work correctly you need to add AsyncModulePlugin
to your plugins.
// webpack.config.js var AsyncModulePlugin = ; moduleexports = // ... plugins: // ... other plugins // ...
Query parameters
-
name
: Use this to specify output name for requested chunk. See webpack documentation -
promise
: Use this to return a promise fromasync-module-loader
. -
noexec
: Use this to delay chunk execution
License
MIT (http://www.opensource.org/licenses/mit-license)