Skip to content

Repository files navigation

licenseBuild Statusnpm versiondependencies StatusdevDependencies StatuspeerDependencies Statusnpm

all-chunks-loaded-webpack-plugin for HTML Webpack Plugin

Provide callback executed after all chunks loaded.

Install via npm

npm install --save-dev all-chunks-loaded-webpack-plugin

Usage

The plugin will update all your webpack chunks with attribute onload contains onload callback. Just add the plugin to your webpack config as follows:

webpack.config.js

constHtmlWebpackPlugin=require('html-webpack-plugin')constAllChunksLoadedWebpackPlugin=require('all-chunks-loaded-webpack-plugin');module.exports={
...
plugins: [newHtmlWebpackPlugin(),newAllChunksLoadedWebpackPlugin({callback: "alert('All chunks loaded!');"}),
...
]}

This will generate a file dist/index.html containing the following:

<!DOCTYPE html><html><head><metacharset="UTF-8"><title>Webpack App</title><scripttype="text/javascript">varallChunksLoadedWebpackPluginLoadedFiles=[];functionallChunksLoadedWebpackPlugin(chunk,file){varallFiles=['app.css','app.js'];if(allChunksLoadedWebpackPluginLoadedFiles.indexOf(file)===-1){allChunksLoadedWebpackPluginLoadedFiles.push(file);if(allChunksLoadedWebpackPluginLoadedFiles.length===allFiles.length){setTimeout(function(){alert('All chunks loaded!');},0);}}}</script><linkhref="app.css" rel="stylesheet" onload="this.onload=null;allChunksLoadedWebpackPlugin('app', 'app.css');"></head><body><scriptsrc="app.js" onload="this.onload=null;allChunksLoadedWebpackPlugin('app', 'app.js');"></script></body></html>

Options

You can pass a hash of configuration options to all-chunks-loaded-webpack-plugin. Allowed values are as follows:

NameTypeDefaultDescription
callback{String}undefinedYour callback called after all chunks loaded
errorCallback{String}undefinedYour callback called if some chunk has loading error
chunks{String[]}undefinedAllows you to callback called only some chunks loaded
excludeChunks{String[]}undefinedAllows you to skip callback called some chunks loaded

Here's an example webpack config illustrating how to use these options:

webpack.config.js

module.exports={
...
plugins: [newHtmlWebpackPlugin(),newAllChunksLoadedWebpackPlugin({callback: '/* Put your callback here */'}),
...
]}

Credit

See also

Need a feature?

Welcome to issues!

About

Provide callback executed after all chunks loaded

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages