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

webpack-custom-hot-update-strategy

v1.0.1

Published

Webpack plugin for customize HMR functions that request and add code of changed modules to the page

Downloads

6

Readme

Webpack Custom Hot Update Strategy

Документация на русском

Webpack plugin that allows you to change the strategy for Hot Module Replacement to receive updated modules when hot: true is enabled.

Installation

npm install --save-dev webpack-custom-hot-update-strategy

In Webpack config file webpack.config.js:

const CustomHotUpdateStrategy = require('webpack-custom-hot-update-strategy');

module.exports = {
    // ... Other Webpack config

    devServer: {
        // ... Other Webpack Dev Server config

        hot: true
    },
    plugins: [
        // ... Other Webpack plugins

        new CustomHotUpdateStrategy()
    ]
};

Configuration

A plugin can take an object with keys update and manifest as an argument:

new CustomHotUpdateStrategy({
    manifest: require('./path_to_implementation'),
    update: require('./path_to_implementation')
});

This plugin contains several options for implementing these functions:

  • manifest: require a function template that loads the module update manifest [publicPath][hash].hot-update.json.

    • hotDownloadManifest:

      require('webpack-custom-hot-update-strategy/strategies/manifest/hotDownloadManifest');

      Applies by default, if no key is specified manifest. This function corresponds to the native function Hot Module Replacement.

  • update: require a function template which takes an argument chunkId, на его основе specifies the path to the file ([publicPath][chunkId].[hash].hot-update.js) and adds the module script to the page.

    • hotDownloadUpdateChunk:

      require('webpack-custom-hot-update-strategy/strategies/update/hotDownloadUpdateChunk');

      Applies by default, if no key is specified update. This function corresponds to the native function Hot Module Replacement: specifies the path to the updated module, creates a new tag <script>, assigns the path as src and append this tag in head.

    • hotDownloadUpdateChunkFetch:

      require('webpack-custom-hot-update-strategy/strategies/update/hotDownloadUpdateChunkFetch');

      Specifies the path to the updated module, makes a request for it using fetch, creates a new tag <script>, inserts the content received from the query and append this tag in head.

    • hotDownloadUpdateChunkFetchEval:

      require('webpack-custom-hot-update-strategy/strategies/update/hotDownloadUpdateChunkFetchEval');

      Specifies the path to the updated module, makes a request for it using fetch, and executes the content, retrieved from the query with eval().

Your own implementation

To write your own implementation of these functions, you need to follow some rules by which the template will be converted into a working function that will fall into the module wrapper.

  • Function wrapper:

    The module should wrap the working functions in an anonymous one, which it returns.

    module.exports = function() {
        // Implementation of the working function
    };
  • The names of the main functions and their arguments must be strictly defined.

    • manifest:

      module.exports = function() {
          function hotDownloadManifest(requestTimeout) {
              // Implementation of the working function
          }
      };
    • update:

      module.exports = function() {
          function hotDownloadUpdateChunk(chunkId) {
              // Implementation of the working function
          }
      };
  • Since many of the values used in these functions are custom, you must replace them with special $expressions$ in the template, which will be replaced with the desired values at compile time.

List of special expressions:

With all of the above in mind, the standard function template for update prop will look like this:

module.exports = function() {
    function hotDownloadUpdateChunk(chunkId) {
        var script = document.createElement('script');
        script.charset = 'utf-8';
        script.src = $require$.p + $hotChunkFilename$;
        if ($crossOriginLoading$) script.crossOrigin = $crossOriginLoading$;
        document.head.appendChild(script);
    }
};