• Stars
    star
    1,433
  • Rank 32,854 (Top 0.7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

webpack plugin for generating asset manifests
webpack-manfiest-plugin

tests cover size libera manifesto

webpack-manifest-plugin

A Webpack plugin for generating an asset manifest.

❤️ 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

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.

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 }

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)

More Repositories

1

jsx-email

Build emails with a delightful DX
TypeScript
924
star
2

koa-webpack

Development and Hot Reload Middleware for Koa2
JavaScript
441
star
3

webpack-plugin-serve

A Development Server in a Webpack Plugin
JavaScript
337
star
4

webpack-nano

A teensy, squeaky 🐤 clean Webpack CLI
JavaScript
237
star
5

gmail-classic

CSS for reverting Gmail to the Classic Theme
CSS
216
star
6

postcss-less

PostCSS Syntax for parsing LESS
JavaScript
123
star
7

webpack-plugin-ramdisk

🐏 A webpack plugin for blazing fast builds on a RAM disk / drive
JavaScript
118
star
8

Gmail-Notifier-Plus

Gmail Notifier Plus
C#
89
star
9

prettier-plugin-package

An opinionated package.json formatter plugin for Prettier
JavaScript
81
star
10

mocha-chrome

☕ Run Mocha tests using headless Google Chrome
JavaScript
72
star
11

apollo-log

A logging extension for the Apollo GraphQL Server
TypeScript
66
star
12

postcss-values-parser

A CSS property value parser for PostCSS
JavaScript
58
star
13

webpack-serve

A CLI for webpack-plugin-serve, providing a premier webpack development server
JavaScript
51
star
14

loglevelnext

A modern logging library for Node.js that provides log level mapping to the console
TypeScript
38
star
15

OctoGerrit

A modern, clean, and usable theme for Gerrit
CSS
29
star
16

koa-ws

Empower your koa.js application with realtime
JavaScript
26
star
17

nanoid-cli

A tiny cli wrapper for nanoid
JavaScript
24
star
18

LiberaManifesto

A Manifesto for Open Source Software and Free Services
HTML
20
star
19

webpack-log

A logger for the Webpack ecosystem
JavaScript
18
star
20

doiuse-email

Lint HTML and CSS for email support against the `Can I email?` database.
TypeScript
14
star
21

Snarf

Snarf is an NFS server implementation written in C# with .NET 4.5.
C#
13
star
22

Brew

Brew is an open source library of interface components for ASP.NET which utilitizes jQuery and jQuery UI.
JavaScript
10
star
23

github-notifications-classic

A CSS project that restores the classic Github Notifications appearance.
CSS
9
star
24

Shellscape.Common

A .NET Library I use in a lot of my projects. Written in C#
C#
7
star
25

harmonica

A module that allows use of Node.js --harmony flags, programmatically.
JavaScript
7
star
26

webpack-hot-client

A client for enabling, and interacting with, webpack Hot Module Replacement
JavaScript
7
star
27

bundler-serve

A Platform for Bundler Development Servers
JavaScript
6
star
28

fwv

A ⚡️ crazy fast streaming ⚡️ Fixed Width Value Parser
JavaScript
5
star
29

gulp-scan

A Gulp plugin to scan a file for a particular string or expression
JavaScript
5
star
30

piilist

A list of Personally Identifiable Information keys / words / phrases used for redaction or removal
JavaScript
3
star
31

thank-you

A place for me to thank the outstanding people who support my work
3
star
32

Lumen

Everything that Start should have been.
C#
3
star
33

dot

Tools for monorepos, serverless, and more
TypeScript
2
star
34

shellscape.github.io

The codebase for shellscape.org
HTML
2
star
35

Gcal-Notifier-Plus

A Google Calendar Notifier for Windows 7
C#
2
star
36

gulp-assist

Display helpful information for your Gulp tasks
JavaScript
2
star
37

babel-plugin-async-to-plain-generator

Transform async functions into non-wrapped ES2015 generators
JavaScript
2
star
38

npm-version-tree

Fetch a dependency version tree for a package
JavaScript
2
star
39

Nubs

Fancy Tabs for the Windows Desktop
C#
1
star
40

travis-target

A Node.js module to determine the file or directory targets of a Travis CI build.
JavaScript
1
star
41

gulp-mocha-chrome

☕ Run Mocha tests using Google Chrome via Gulp
JavaScript
1
star
42

prettier-tree

Prettier directory trees
1
star
43

Rumshot

1
star
44

eslint-config-shellscape

ESLint shareable config for my projects
JavaScript
1
star
45

gulp-version-conflicts

Check for and report on module version conflicts for a package
JavaScript
1
star