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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bundle-ensure-webpack-plugin

v1.1.1

Published

ensure bundle installed and make retry-able before startup

Readme

bundle-ensure-webpack-plugin Build Status npm version

Ensure bundle installed and make it retry-able before startup.

Purpose

We know that webpack don't care about how bundle/script loaded, and our entry bundle will be execute immediately.

Assume there were muti chunks (commonChunks/splitedChunks) or other bundles (externals, Dlls) on the page:

<script src="./dll/common.bundle.js"></script>
<script src="./commonChunk.bundle.js"></script>
<script src="./entry.bundle.js"></script>

Meanwhile if one of them failed to load, the entry will still be executed and end with throw exception:

image

image

A issue on webpack.

We have no chance to detect or reload the missing bundle on webpack. Unless we use an entire of script load system (such as requireJS) to load all of them in the application, but it's too heavy, at least to me.

So the bundle-ensure-webpack-plugin is what I made for solve this problem:

  • make a wrap to each chunk, prevent the immediate execution. (Compile-time)

  • output entry's chunk manifest which includes common chunks, externals, dlls, then inline to the page (auto-associate with html-webpack-plugin) along with startup code. (Compile-time)

  • check first and ensure all of these things have existed before running the entry. (Run-time)

  • make a hook to retry/reload each missing item. (Run-time)

If you are using quite a few split-bundles or externals(with webpack) and have a strong demand for load/reload guarantee (For example, serving for some regions which have weak-network or hijacked frequently). you could try this plugin.

Install

yarn add bundle-ensure-webpack-plugin

Tips: If you're using webpack v2~3, please use the old version: [email protected].

Useage

Just add the plugin in your webpack.config.js

const BundleEnsureWebpackPlugin = require("bundle-ensure-webpack-plugin");
module.exports = {
  entry: "./entry.js",
  output: {
    filename: "[name].js"
    path: path.resolve(__dirname, "./dist"),
    publicPath:"https://cdn1.com/", 
  },
  optimization: {
    minimize: false,
    splitChunks: {
      chunks: "all",
      minSize: 0,
      cacheGroups: {
        common: {
          name: "common",
          test: /lib/,
          minSize: 0
        }
      }
    }
  },
  plugins:[
    new HtmlWebpackPlugin(),

    new BundleEnsureWebpackPlugin({
      // Provide a alternative publicPath for chunk reload.
      publicPath:"https://cdn2.com/", 
    }),
  ]
};

It also can find dlls/externals and reload them when they were lost.

module.exports = {
  //...
  externals:{
    jQuery:"jQuery",
  },
  plugins:[
    new webpack.DllReferencePlugin({
      name: "myDll",
      manifest: require("./dist/myDll-manifest.json")
    }),

    new BundleEnsureWebpackPlugin({
      // Provide urls for externals reload when lost.
      externals:{
        myDll: "https://cdn2.com/dist/myDll.js",
        jQuery: "https://code.jquery.com/jquery-3.2.1.min.js", 
      }
    }),
  ]
};

Work fine with muti page(muti html-webpack-plugin):

module.exports = {
  entry: {
    entry1: path.resolve(__dirname,"./entry1.js"),
    entry2: path.resolve(__dirname,"./entry2.js"),
  },
  //...

  plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: "common",
      filename: "commonChunk.js",
    }),

    new HtmlWebpackPlugin({
      chunks:["common", "entry1"],
      filename: "index1.html",
    }),
    new HtmlWebpackPlugin({
      chunks:["common", "entry2"], 
      filename: "index2.html",
    }),

    new BundleEnsureWebpackPlugin({
      publicPath:"https://cdn2.com/", 
    }),
  ]
};

See examples.

Options

  • externals: Object. Provide reload URL for each external.

  • publicPath: String. Provide an alternative publicPath for chunk reload.

  • appendTime: Default is true, append timestamp to retry URL's querystring to avoid cache.

  • associateWithHtmlPlugin: Default is true, auto inline the startup code into the HTML page with html-webpack-plugin.

  • retryTemplate: String. Default is "default". You can pass a plain javascript code snippet as your own retry handler which will be inserted into startup code. See the retry template)

  • emitStartup: Default is false. Output each entry point's startup code to disk. the startup code should be inline to the page to avoid load failure. So it's not recommended to use unless you are using another way who need it such as server rendering.

  • startupFilename: String. Default is [name].startup.js. Only available while emitStartup has enabled. (Files will be outputted to your webpackOptions.output.path).

License

MIT.