Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webpack-manifest-plugin

Package Overview
Dependencies
Maintainers
2
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webpack-manifest-plugin - npm Package Compare versions

Comparing version 3.0.0-rc.0 to 3.0.0

lib/helpers.js

117

package.json
{
"name": "webpack-manifest-plugin",
"version": "3.0.0-rc.0",
"description": "webpack plugin for generating asset manifests",
"main": "index.js",
"scripts": {
"test": "jest",
"codecov": "codecov"
},
"version": "3.0.0",
"description": "A Webpack Plugin for generating Asset Manifests",
"license": "MIT",
"repository": "shellscape/webpack-manifest-plugin",
"author": "Dane Thurber <dane.thurber@gmail.com>",
"license": "MIT",
"homepage": "https://github.com/shellscape/webpack-manifest-plugin",
"bugs": "https://github.com/shellscape/webpack-manifest-plugin/issues",
"main": "lib/index.js",
"engines": {
"node": ">=6.11.5"
"node": ">=10.22.1"
},
"scripts": {
"ci:coverage": "nyc npm run ci:test && nyc report --reporter=text-lcov > coverage.lcov",
"ci:lint": "npm run lint && npm run security",
"ci:test": "npm run test -- --verbose",
"lint": "npm run lint:docs && npm run lint:json && npm run lint:package && npm run lint:js",
"lint-staged": "lint-staged",
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md",
"lint:js": "eslint --fix --cache lib test",
"lint:json": "prettier --write codecov.yml .circleci/config.yml .eslintrc",
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package",
"posttest": "npm install webpack@^4.44.2",
"security": "npm audit --audit-level=moderate",
"test": "npm run test:v4 && npm run test:v5",
"test:v4": "ava",
"test:v5": "npm install webpack@^5.0.0 --no-save && ava"
},
"files": [
"lib",
"README.md",
"LICENSE"
],
"peerDependencies": {
"webpack": "4"
"webpack": ">=4.44.2"
},
"dependencies": {
"tapable": "^2.0.0",
"webpack-sources": "^2.2.0"
},
"devDependencies": {
"@svgr/webpack": "^4.3.3",
"codecov": "^3.6.1",
"css-loader": "^3.2.0",
"file-loader": "^4.2.0",
"jest": "^24.9.0",
"@ava/babel": "^1.0.1",
"@svgr/webpack": "^5.4.0",
"ava": "^3.13.0",
"codecov": "^3.1.0",
"copy-webpack-plugin": "^6.2.1",
"css-loader": "^1.0.0",
"del": "^6.0.0",
"eslint-config-shellscape": "^2.1.0",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^2.0.0",
"lint-staged": "^10.4.0",
"memory-fs": "^0.4.1",
"mini-css-extract-plugin": "^0.8.0",
"react": "^16.9.0",
"rimraf": "^3.0.0",
"style-loader": "^1.0.0",
"webpack": "^4.41.0"
"nyc": "^15.1.0",
"pre-commit": "^1.2.2",
"prettier": "^2.1.2",
"prettier-plugin-package": "^1.2.0",
"react": "^16.3.2",
"style-loader": "^0.23.0",
"webpack": "^4.44.2",
"webpack-merge": "^5.2.0"
},
"files": [
"index.js",
"lib"
],
"repository": {
"type": "git",
"url": "https://github.com/danethurber/webpack-manifest-plugin.git"
"ava": {
"files": [
"!**/fixtures/**",
"!**/helpers/**",
"!**/output/**"
]
},
"bugs": {
"url": "https://github.com/danethurber/webpack-manifest-plugin/issues"
},
"homepage": "https://github.com/danethurber/webpack-manifest-plugin",
"dependencies": {
"fs-extra": "^8.1.0",
"lodash": "^4",
"tapable": "^1.1.3"
},
"jest": {
"testEnvironment": "node",
"coverageDirectory": "./coverage/",
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"<rootDir>/spec/helpers/"
"collectCoverage": true
},
"lint-staged": {
"*.js": [
"eslint --fix"
]
}
},
"maintainers": [
"Andrew Powell <andrew@shellscape.org>"
],
"nyc": {
"include": [
"lib/*.js"
],
"exclude": [
"test/"
]
},
"pre-commit": "lint-staged"
}

@@ -1,55 +0,85 @@

# Webpack Manifest Plugin [![Build Status](https://travis-ci.org/danethurber/webpack-manifest-plugin.svg?branch=master)](https://travis-ci.org/danethurber/webpack-manifest-plugin) [![codecov](https://codecov.io/gh/danethurber/webpack-manifest-plugin/badge.svg?branch=master)](https://codecov.io/gh/danethurber/webpack-manifest-plugin?branch=master) [![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/webpack-manifest-plugin#)
[tests]: https://img.shields.io/circleci/project/github/shellscape/webpack-manifest-plugin.svg
[tests-url]: https://circleci.com/gh/shellscape/webpack-manifest-plugin
[cover]: https://codecov.io/gh/shellscape/webpack-manifest-plugin/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/shellscape/webpack-manifest-plugin
Webpack plugin for generating an asset manifest.
[size]: https://packagephobia.now.sh/badge?p=webpack-manifest-plugin
[size-url]: https://packagephobia.now.sh/result?p=webpack-manifest-plugin
> NOTE: The following is related to the next major version of `webpack-manifest-plugin`, please check https://github.com/danethurber/webpack-manifest-plugin/blob/1.x/README.md for `v1` documentation
<div align="center">
<img width="256" src="https://raw.githubusercontent.com/shellscape/webpack-manifest-plugin/master/assets/manifest.svg?sanitize=true" alt="webpack-manfiest-plugin"><br/><br/>
</div>
[![tests][tests]][tests-url]
[![cover][cover]][cover-url]
[![size][size]][size-url]
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com)
# webpack-manifest-plugin
A Webpack plugin for generating an asset manifest.
:heart: Please consider [Sponsoring my work](https://github.com/sponsors/shellscape)
## Requirements
`webpack-manifest-plugin` is an [evergreen 🌲](./.github/FAQ.md#what-does-evergreen-mean) module.
This module requires an [Active LTS](https://github.com/nodejs/Release) Node version (v10.0.0+) and Webpack v4.44.0+.
## Install
```bash
npm install --save-dev webpack-manifest-plugin
Using npm:
```console
npm install webpack-nano webpack-manifest-plugin --save-dev
```
_Note: We recommend using [webpack-nano](https://github.com/shellscape/webpack-nano), a very tiny, very clean webpack CLI._
## Usage
In your `webpack.config.js`
Create a `webpack.config.js` file:
```javascript
var ManifestPlugin = require('webpack-manifest-plugin');
```js
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const options = { ... };
module.exports = {
// ...
plugins: [
new ManifestPlugin()
]
// an example entry definition
entry: [ 'app.js' ],
...
plugins: [
new WebpackManifestPlugin(options)
]
};
```
This will generate a `manifest.json` file in your root output directory with a mapping of all source file names to their corresponding output file, for example:
And run `webpack`:
```console
$ npx wp
...
With the default options, the example above will create a `manifest.json` file in the output directory for the build. The manfist file will contain a map of source filenames to the corresponding build output file. e.g.
```json
{
"mods/alpha.js": "mods/alpha.1234567890.js",
"mods/omega.js": "mods/omega.0987654321.js"
"dist/batman.js": "dist/batman.1234567890.js",
"dist/joker.js": "dist/joker.0987654321.js"
}
```
### Options
## API:
### `basePath`
```js
// webpack.config.js
Type: `String`<br>
Default: `''`
module.exports = {
output: {
publicPath
},
plugins: [
new ManifestPlugin(options)
]
}
```
Specifies a path prefix for all keys in the manifest. Useful for including your output path in the manifest.
### `options.fileName`
### `fileName`

@@ -59,77 +89,102 @@ Type: `String`<br>

The manifest filename in your output directory.
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.
### `options.publicPath`
### `filter`
Type: `String`
Default: `output.publicPath`
Type: `Function`<br>
Default: `undefined`
A path prefix that will be added to values of the manifest.
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.
### `options.basePath`
### `generate`
Type: `String`
Type: `Function`<br>
Default: `undefined`
A path prefix for all keys. Useful for including your output path in the manifest.
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`
### `options.writeToFileEmit`
Type: `Function`<br>
Default: `undefined`
Type: `Boolean`<br>
Default: `false`
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.
If set to `true` will emit to build folder and memory in combination with `webpack-dev-server`
### `publicPath`
Type: `String`<br>
Default: `<webpack-config>.output.publicPath`
### `options.seed`
A path prefix that will be added to values of the manifest.
### `removeKeyHash`
Type: `RegExp | Boolean`<br>
Default: `/([a-f0-9]{32}\.?)/gi`
If set to a valid `RegExp`, removes hashes from manifest keys. e.g.
```json
{
"index.c5a9bff71fdfed9b6046.html": "index.c5a9bff71fdfed9b6046.html"
}
```
```json
{
"index.html": "index.c5a9bff71fdfed9b6046.html"
}
```
The default value for this option is a regular expression targeting Webpack's [default md5 hash](https://webpack.js.org/configuration/output/#outputhashfunction). 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`<br>
Default: `{}`
A cache of key/value pairs to used to seed the manifest. This may include a set of [custom key/value](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json) pairs to include in your manifest, or may be used to combine manifests across compilations in [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler). To combine manifests, pass a shared seed object to each compiler's ManifestPlugin instance.
A cache of key/value pairs to used to seed the manifest. This may include a set of [custom key/value](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json) pairs to include in your manifest, or may be used to combine manifests across compilations in [multi-compiler mode](https://github.com/webpack/webpack/tree/master/examples/multi-compiler). To combine manifests, pass a shared seed object to each compiler's `WebpackManifestPlugin` instance.
### `options.filter`
### `serialize`
Type: `Function(FileDescriptor): Boolean`
Type: `Function(Object) => string`<br>
Default: `undefined`
Filter out files. [FileDescriptor typings](#filedescriptor)
A `Function` which can be leveraged to serialize the manifest in a different format than json. e.g. `yaml`.
### `sort`
### `options.map`
Type: `Function`<br>
Default: `undefined`
Type: `Function(FileDescriptor): FileDescriptor`
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.
Modify files details before the manifest is created. [FileDescriptor typings](#filedescriptor)
### `useEntryKeys`
### `options.sort`
Type: `Boolean`<br>
Default: `false`
Type: `Function(FileDescriptor): number`
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).
Sort files before they are passed to `generate`. [FileDescriptor typings](#filedescriptor)
### `writeToFileEmit`
### `options.generate`
Type: `Boolean`<br>
Default: `false`
Type: `Function(Object, FileDescriptor, string[]): Object`<br>
Default: `(seed, files, entrypoints) => files.reduce((manifest, {name, path}) => ({...manifest, [name]: path}), seed)`
If `true`, will emit the manifest to the build directory _and_ in memory for compatibility with `webpack-dev-server`.
Create the manifest. It can return anything as long as it's serialisable by `JSON.stringify`. [FileDescriptor typings](#filedescriptor)
### `options.serialize`
## Manifest File Descriptor
Type: `Function(Object): string`<br>
Default: `(manifest) => JSON.stringify(manifest, null, 2)`
This plugin utilizes the following object structure to work with files. Many options for this plugin utilize the structure below.
Output manifest file in different format then json (i.e. yaml).
## FileDescriptor
```ts
FileDescriptor {
path: string;
name: string | null;
isInitial: boolean;
isChunk: boolean;
{
chunk?: Chunk;
isAsset: boolean;
isChunk: boolean;
isInitial: boolean;
isModuleAsset: boolean;
name: string | null;
path: string;
}

@@ -142,3 +197,3 @@ ```

Only available is `isChunk` is `true`
Only available if `isChunk` is `true`

@@ -157,5 +212,35 @@ ### `isInitial`

## Compiler Hooks
## License
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.
MIT © [Dane Thurber](https://github.com/danethurber)
### `getCompilerHooks`
Returns: `{ afterEmit: SyncWaterfallHook, beforeEmit: SyncWaterfallHook }`
#### Usage
```js
const { getCompilerHooks } = require('webpack-manifest-plugin');
class BatmanPlugin {
apply(compiler) {
const { beforeEmit } = getCompilerHooks(compiler);
beforeEmit.tap('BatmanPlugin', (manifest) => {
return { ...manifest, name: 'hello' };
})
}
}
```
## Attiribution
Special thanks to [Dane Thurber](https://github.com/danethurber), the original author of this plugin, without whom this plugin would not exist.
## Meta
[CONTRIBUTING](./.github/CONTRIBUTING.md)
[LICENSE (MIT)](./LICENSE)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc