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

update-chunk-links-in-files-webpack-plugin

v1.0.4

Published

a WebPack plugin which updates chunk links in HTML/PHP/ASPX files

Downloads

3

Readme

Update Chunk Links In Files Webpack Plugin

This plugin replaces chunk file names (links) in given list of files.

It's meant to solve the problem of updating file names inside HTML / ASPX / PHP / etc. files when chunk names contain a hash, which changes every time a new version of the file is created by WebPack.

In case you are not using Webpack to build your HTML / ASPX / PHP files, this plugin will solve that problem!

Installation

$ npm install update-chunk-links-in-files-webpack-plugin --save-dev

Example

Webpack.config.js

First let's have a look at WebPack config file (unimportant bits are omitted for brevity).

Notice that the file names in the output section contain [contenthash], which changes each time the content of the file changes.

const path = require('path');
const UpdateChunkLinksInFilesWebpackPlugin = require('update-chunk-links-in-files-webpack-plugin');

module.exports = {

    entry: {
        "app": path.resolve("src/index.js")
    },
    output: {
        // chunk names contain `contenthash`
        filename: "[name].[contenthash].bundle.js",
        chunkFilename: "[name].[contenthash].bundle.js"
    },

    /* ... your usual WebPack stuff goes here ... */

    plugins: [
        new UpdateChunkLinksInFilesWebpackPlugin({
            // files containing links to chunks, which need to be updated
            replaceInFiles: [
                path.resolve(__dirname, '_site/master-pages/default.aspx')
            ],
            // regexp patterns to be used to find chunk names in the file
            chunkNamePatterns: [
                /vendor\.[a-z0-9]+\.bundle\.js/g,
                /app\.[a-z0-9]+\.bundle\.js/g
            ],
            // (optional) regexp anti-patterns which can be used to exclude
            // chunk names from being inserted into HTML ... i.e. source maps
            chunkNameAntiPatterns: [
                /vendor\.[a-z0-9]+\.bundle\.js.map/g,
                /app\.[a-z0-9]+\.bundle\.js.map/g
            ]
        })
    ]
};

HTML

The following snippet shows the default.aspx file, which is indicated in the WebPack config

Each time any of the bundle files changes the plugin will update the ASPX file accordingly.

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <p>Hello World</p>
    <script src="/script/vendor.0f8f98e02847fe61032d.bundle.js"></script>
    <script src="/script/app.f0c4c1d45df3e888a309.bundle.js" async></script>
</body>
</html>

License

MIT