Bundle Loader
Bundle loader for webpack.
Install
npm i bundle-loader --save
var waitForChunk = require("bundle-loader!./file.js");
waitForChunk(function(file) {
});
waitForChunk(callbackTwo);
waitForChunk(callbackThree);
The file is requested when you require the bundle loader. If you want it to request it lazy, use:
var load = require("bundle-loader?lazy!./file.js");
load(function(file) {
});
name
query parameter
You may set name for a bundle using the name
query parameter.
See documentation.
Note chunks created by the loader will be named according to the
output.chunkFilename
rule, which defaults to [id].[name]
.
Here [name]
corresponds to the chunk name set in the name
query parameter.
Example:
require("bundle-loader?lazy&name=my-chunk!./file.js");
require("bundle-loader?lazy&name=[name]!./file.js");
And the webpack configuration:
module.exports = {
entry: { ... },
output : {
path : ...,
filename : '[name].js',
chunkFilename : '[name]-[id].js',
},
}
Normal chunks will show up using the filename
rule above, and be named according to their chunkname.
Chunks from bundle-loader
, however will load using the chunkFilename
rule, so the example files will produce my-chunk-1.js
and file-2.js
respectively.
You can also use chunkFilename
to add hash values to the filename, since putting [hash]
in the bundle query parameter does not work correctly.
Maintainers