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 = ;const UpdateChunkLinksInFilesWebpackPlugin = ; moduleexports = entry: "app": path output: // chunk names contain `contenthash` filename: "[name].[contenthash].bundle.js" chunkFilename: "[name].[contenthash].bundle.js" /* ... your usual WebPack stuff goes here ... */ plugins: // files containing links to chunks, which need to be updated replaceInFiles: path // 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.
Hello World
License
MIT