enhanced-webpack-chunk-rename-plugin

1.0.3 • Public • Published

npm node

enhanced-webpack-chunk-rename-plugin

This plugin helps with chunk naming in webpack. To use it you need at least webpack 4.1

enhancement

  • initial vendor chunks split by SplitChunksPlugin will be fine
  • initial css chunks split by MiniCssExtractPlugin will be fine

Install

npm install webpack-chunk-rename-plugin --save-dev

or if you are using yarn

yarn add webpack-chunk-rename-plugin --dev

Usage

const ChunkRenamePlugin = require("webpack-chunk-rename-plugin");
 
module.exports = {
  ...
  plugins: [
    new ChunkRenamePlugin(objectWithOptions),
  ],
}
Option Type Description
initialChunks boolean\|string Rename all chunks which are satisfy the condition chunk.isOnlyInitial. If true is passed then use output.filename option, if string is passed, use it as chunk name i.e. you can use all placeholder for chunk naming like [hash],[name],[chunkhash] etc.
initialCssChunks string Use provided string to rename all initial css chunks split by MiniCssExtractPlugin. Just like for previous option, standart placeholders could be used.
asyncChunks string Use provided string to rename all async chunks. Just like for previous option, standart placeholders could be used.
[chunkName] string Use provided string to rename specific chunk.

Examples

The result of the code below will be: use filename option for all chunks with entry and "specialName.[name].js" template for mySpecialChunk chunk (assuming you're not using it as a test option for splitChunks.cacheGroups).

module.exports = {
  output: {
    filename: "[name].js",
    chunkFilename: "[name].[chunkhash].js",
  },
  entry: {
    mySpecialChunk: "path/to/my/chunk",
    ....
  },
  ....
  plugins: [
    new ChunkRenamePlugin({
      initialChunks: true,
      mySpecialChunk: "specialName.[name].js",
    }),
  ],
}

Motivation

Currently if you want to move webpack runtime into the separate file you will use optimization.runtimeChunk option, you all of the chunks, which do not have runtime in them will use output.chunkFilename for the filename, event if it contains entry. See issue.
There are a few plugins for chunk renaming, however i haven't found plugin that is compatible with webpack 4.

Package Sidebar

Install

npm i enhanced-webpack-chunk-rename-plugin

Weekly Downloads

36

Version

1.0.3

License

MIT

Unpacked Size

46.6 kB

Total Files

16

Last publish

Collaborators

  • madlord