npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

all-chunks-loaded-webpack-plugin

v0.3.0

Published

Provide callback executed after all chunks loaded

Downloads

10

Readme

license Build Status npm version dependencies Status devDependencies Status peerDependencies Status npm

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
  • Latest release: https://github.com/devpreview/all-chunks-loaded-webpack-plugin/releases
  • NPM: https://www.npmjs.com/package/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

const HtmlWebpackPlugin = require('html-webpack-plugin')
const AllChunksLoadedWebpackPlugin = require('all-chunks-loaded-webpack-plugin');

module.exports = {
  ...
  
  plugins: [
    new HtmlWebpackPlugin(),
    new AllChunksLoadedWebpackPlugin({
      callback: "alert('All chunks loaded!');"
    }),
    ...
  ]
}

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

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
    <script type="text/javascript">
      var allChunksLoadedWebpackPluginLoadedFiles = [];
      function allChunksLoadedWebpackPlugin(chunk, file) {
        var allFiles = ['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>
    <link href="app.css" rel="stylesheet" onload="this.onload=null;allChunksLoadedWebpackPlugin('app', 'app.css');">
  </head>
  <body>
    <script src="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:

|Name|Type|Default|Description| |:--:|:--:|:-----:|:----------| |callback|{String}|undefined|Your callback called after all chunks loaded| |errorCallback|{String}|undefined|Your callback called if some chunk has loading error| |chunks|{String[]}|undefined|Allows you to callback called only some chunks loaded| |excludeChunks|{String[]}|undefined|Allows 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: [
    new HtmlWebpackPlugin(),
    new AllChunksLoadedWebpackPlugin({
      callback: '/* Put your callback here */'
    }),
    ...
  ]
}

Credit

See also

Need a feature?

Welcome to issues!