split-chunk-loader
v1.0.2
Published
split chunk loader module for webpack
Downloads
46
Readme
split-chunk-loader for webpack
A Webpack bundle-loader that supports bundle loading error callbacks.
Credits
This loader is a fork of the bundle-loader.
The original fork was created in the require-error-handler-webpack-plugin
Installation
require.ensure error handling must be activated in webpack for this loaded to work
Webpack 1.x
npm install require-error-handler-webpack-plugin --save-dev
Follow the instructions for configuring the require-error-handler-webpack-plugin
npm install split-chunk-loader --save-dev
Webpack >= 2.2 < 2.4
npm install require-ensure-error-webpack-plugin --save-dev
Follow the instructions for configuring the require-ensure-error-webpack-plugin
Webpack >= 2.4
The require-ensure-error-webpack-plugin is no longer needed with Webpack 2.4 and above since the feature has been merged into Webpack itself.
npm install split-chunk-loader --save-dev
Usage
// The chunk is requested, when you require it
var waitForChunk = require("split-chunk-loader!./file.js");
// To wait until the chunk is available (and get the exports)
// you need to async wait for it.
waitForChunk(function(file) {
// use file like is was required with
// var file = require("./file.js");
}, function(error) {
// do something with the error
});
// wraps the require in a require.ensure block
The file is requested when you require the split chunk loader. If you want it to request it lazily, use:
var load = require("split-chunk-loader?lazy!./file.js");
// The chunk is not requested until you call the load function
load(function(file) {
}, function(error) {
});
You may set the name for the chunk bundle file (name
query parameter). See documentation.
require("split-chunk-loader?lazy&name=my-chunk!./file.js"); // #.my-chunk.js
require("split-chunk-loader?name=my-chunk-[name]!./path/the-file.js"); // #.my-chunk-the-file.js
License
MIT (http://www.opensource.org/licenses/mit-license.php)