Which is Better Webpack Manifest Plugins?
webpack-manifest-plugin vs webpack-assets-manifest
1 Year
webpack-manifest-pluginwebpack-assets-manifest
What's Webpack Manifest Plugins?

Webpack manifest plugins are tools used in the Webpack build process to generate a manifest file that maps original asset filenames to their corresponding output filenames. This is particularly useful for cache-busting and ensuring that the correct files are referenced in your HTML or other assets. The two packages, 'webpack-assets-manifest' and 'webpack-manifest-plugin', serve similar purposes but have different features and use cases, making them suitable for different project requirements.

NPM Package Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
webpack-manifest-plugin3,617,9811,43536.7 kB3-MIT
webpack-assets-manifest673,60032347.6 kB118 months agoMIT
Feature Comparison: webpack-manifest-plugin vs webpack-assets-manifest

Customization Options

  • webpack-manifest-plugin: This plugin provides basic customization options, such as specifying the output file name and the path for the manifest. However, it is less flexible than 'webpack-assets-manifest' in terms of output structure and additional metadata, focusing instead on simplicity and ease of use.
  • webpack-assets-manifest: This package offers extensive customization options, allowing developers to define the structure of the output manifest file, including the ability to include additional metadata for each asset. You can customize the output format, specify which assets to include or exclude, and even manipulate the keys in the manifest to suit your needs.

Integration with Other Plugins

  • webpack-manifest-plugin: This plugin is designed to work seamlessly with other Webpack plugins, particularly those related to asset management. It is straightforward to integrate with existing Webpack configurations, making it a good choice for developers who want to quickly set up asset management without additional complexity.
  • webpack-assets-manifest: It integrates well with other Webpack plugins and loaders, allowing for a more cohesive build process. You can easily combine it with plugins that handle versioning, caching, or other asset management tasks, making it a versatile choice for complex projects.

Performance Impact

  • webpack-manifest-plugin: This plugin is lightweight and designed to have minimal impact on build performance. It is optimized for speed, making it a good choice for projects where build time is a critical factor and where a simple manifest generation is sufficient.
  • webpack-assets-manifest: Due to its extensive customization capabilities, this plugin might introduce a slight overhead in build performance, especially in larger projects with complex configurations. However, the trade-off is often worth it for the added flexibility and control it provides over the manifest generation process.

Learning Curve

  • webpack-manifest-plugin: This plugin has a gentler learning curve, making it accessible for developers who are new to Webpack or asset management. Its straightforward setup and minimal configuration requirements allow for quick integration into projects.
  • webpack-assets-manifest: This package may have a steeper learning curve due to its extensive configuration options and flexibility. Developers may need to invest time in understanding how to leverage its features effectively, especially in larger projects with specific requirements.

Use Case Suitability

  • webpack-manifest-plugin: Ideal for smaller to medium-sized projects where quick setup and ease of use are prioritized. It works well for standard asset management needs without the requirement for extensive customization, making it a go-to choice for many developers.
  • webpack-assets-manifest: Best suited for projects that require detailed control over asset management and manifest generation, such as large applications with specific caching strategies or custom asset naming conventions. It is ideal for teams that need to maintain a complex build process with tailored asset handling.
How to Choose: webpack-manifest-plugin vs webpack-assets-manifest
  • webpack-manifest-plugin: Choose 'webpack-manifest-plugin' if you prefer a straightforward and easy-to-use plugin that automatically generates a manifest file with minimal configuration. It is well-suited for standard use cases where you want to quickly integrate asset management without extensive customization.
  • webpack-assets-manifest: Choose 'webpack-assets-manifest' if you need a more customizable solution that allows you to define how assets are structured in the manifest file. It is ideal for projects that require a specific format or additional metadata in the manifest, as it provides extensive configuration options.
README for webpack-manifest-plugin
webpack-manfiest-plugin

tests cover size libera manifesto

webpack-manifest-plugin

A Webpack plugin for generating an asset manifest.

:heart: Please consider Sponsoring my work

Requirements

webpack-manifest-plugin is an evergreen 🌲 module.

This module requires an Active LTS Node version (v12.0.0+) and Webpack v5.0.0.

Contributing

This repository leverages pnpm for dependency management.

To begin, please install pnpm:

$ npm install pnpm -g

Install

Using npm:

npm install webpack-nano webpack-manifest-plugin --save-dev

Note: We recommend using webpack-nano, a very tiny, very clean webpack CLI.

Usage

Create a webpack.config.js file:

const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const options = { ... };

module.exports = {
	// an example entry definition
	entry: [ 'app.js'	],
  ...
  plugins: [
    new WebpackManifestPlugin(options)
  ]
};

And run webpack:

$ npx wp

With the default options, the example above will create a manifest.json file in the output directory for the build. The manifest file will contain a map of source filenames to the corresponding build output file. e.g.

{
  "dist/batman.js": "dist/batman.1234567890.js",
  "dist/joker.js": "dist/joker.0987654321.js"
}

Options

basePath

Type: String
Default: ''

Specifies a path prefix for all keys in the manifest. Useful for including your output path in the manifest.

fileName

Type: String
Default: manifest.json

Specifies the file name to use for the resulting manifest. By default the plugin will emit manifest.json to your output directory. Passing an absolute path to the fileName option will override both the file name and path.

filter

Type: Function
Default: undefined

Allows filtering the files which make up the manifest. The passed function should match the signature of (file: FileDescriptor) => Boolean. Return true to keep the file, false to remove the file.

generate

Type: Function
Default: undefined

A custom Function to create the manifest. The passed function should match the signature of (seed: Object, files: FileDescriptor[], entries: string[]) => Object and can return anything as long as it's serialisable by JSON.stringify.

map

Type: Function
Default: undefined

Allows modifying the files which make up the manifest. The passed function should match the signature of (file: FileDescriptor) => FileDescriptor where an object matching FileDescriptor is returned.

publicPath

Type: String
Default: <webpack-config>.output.publicPath

A path prefix that will be added to values of the manifest.

removeKeyHash

Type: RegExp | false
Default: /([a-f0-9]{32}\.?)/gi

If set to a valid RegExp, removes hashes from manifest keys. e.g.

{
  "index.c5a9bff71fdfed9b6046.html": "index.c5a9bff71fdfed9b6046.html"
}
{
  "index.html": "index.c5a9bff71fdfed9b6046.html"
}

The default value for this option is a regular expression targeting Webpack's default md5 hash. To target other hashing functions / algorithms, set this option to an appropriate RegExp. To disable replacing the hashes in key names, set this option to false.

seed

Type: Object
Default: {}

A cache of key/value pairs used to seed the manifest. This may include a set of custom key/value pairs to include in your manifest, or may be used to combine manifests across compilations in multi-compiler mode. To combine manifests, pass a shared seed object to each compiler's WebpackManifestPlugin instance.

serialize

Type: Function(Object) => string
Default: undefined

A Function which can be leveraged to serialize the manifest in a different format than json. e.g. yaml.

sort

Type: Function
Default: undefined

Allows sorting the files which make up the manifest. The passed function should match the signature of (fileA: FileDescriptor, fileB: FileDescriptor) => Number. Return 0 to indicate no change, -1 to indicate the file should be moved to a lower index, and 1 to indicate the file shoud be moved to a higher index.

useEntryKeys

Type: Boolean
Default: false

If true, the keys specified in the entry property will be used as keys in the manifest. No file extension will be added (unless specified as part of an entry property key).

useLegacyEmit

Type: Boolean
Default: false

If true, the manifest will be written on the deprecated webpack emit hook to be compatible with not yet updated webpack plugins.

A lot of webpack plugins are not yet updated to match the new webpack 5 API. This is a problem when other plugins use the deprecated emit hook. The manifest will be written before these other plugins and thus files are missing on the manifest.

writeToFileEmit

Type: Boolean
Default: false

If true, will emit the manifest to the build directory and in memory for compatibility with webpack-dev-server.

Manifest File Descriptor

This plugin utilizes the following object structure to work with files. Many options for this plugin utilize the structure below.

{
  chunk?: Chunk;
  isAsset: boolean;
  isChunk: boolean;
  isInitial: boolean;
  isModuleAsset: boolean;
  name: string | null;
  path: string;
}

chunk

Type: Chunk

Only available if isChunk is true

isInitial

Type: Boolean

Is required to run you app. Cannot be true if isChunk is false.

isModuleAsset

Type: Boolean

Is required by a module. Cannot be true if isAsset is false.

Compiler Hooks

This plugin supports the following hooks via the getCompilerHooks export; afterEmit, beforeEmit. These hooks can be useful, e.g. changing manifest contents before emitting to disk.

getCompilerHooks

Returns: { afterEmit: SyncWaterfallHook, beforeEmit: SyncWaterfallHook }

assetHookStage

Type: Number Default: Infinity

If you need to consume the output of this plugin in another plugin, it can be useful to adjust the stage at which the manifest is generated. Pass a new stage to assetHookStage to change when the manifest is generated. See the docs on processAssets for more detail.

Note: any files added to the compilation after the stage specified will not be included in the manifest.

Usage

const { getCompilerHooks } = require('webpack-manifest-plugin');

class BatmanPlugin {
  apply(compiler) {
    const { beforeEmit } = getCompilerHooks(compiler);

    beforeEmit.tap('BatmanPlugin', (manifest) => {
      return { ...manifest, name: 'hello' };
    });
  }
}

Notes

  • If using this plugin with webpack-clean and webpack-dev-server, please review this issue.

Attiribution

Special thanks to Dane Thurber, the original author of this plugin, without whom this plugin would not exist.

Meta

CONTRIBUTING

LICENSE (MIT)