Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Docs #104

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,31 @@ Type: `function`

Filter out files. [more details](#hooks-options)

**Use-case**: Omit [dll-chunks] ([issue](https://github.com/danethurber/webpack-manifest-plugin/issues/46)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not specific to dll chunks, also dynamic one (when you use import(...).then(...))

```js
filter: ({chunk, file}) => {
return chunk.isInitial();
}
```
You can generate additional manifest-file with a dll-chunks only using the [DllPlugin].

[dll-chunks]: https://webpack.js.org/guides/code-splitting/#dynamic-imports
[DllPlugin]: https://webpack.js.org/plugins/dll-plugin/

### `options.map`

Type: `function`

Modify files details before the manifest is created. [more details](#hooks-options)

**Use-case**: Add hash information to manifest file for [SRI] ([issue](https://github.com/danethurber/webpack-manifest-plugin/issues/35), [issue](https://github.com/danethurber/webpack-manifest-plugin/issues/55)):
```js
map: ({chunk, file}) => ({ file, hash: chunk.source.integrity }),
generate: (seed, files) => files.reduce((manifest, {name, path}) => manifest), seed),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is working?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure too 😂
I just rewrited from reduce to generate

after:

map: ({chunk, file}) => {
  return {
    file,
    hash: chunk.source.integrity
  };
}

reduce: (manifest, {chunk, file}) => {
  return manifest;
}

default generate is:

`(seed, files) => files.reduce((manifest, {name, path}) => ({...manifest, [name]: path}), seed)`

```

[SRI]: https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity

### `options.sort`

Type: `function`
Expand All @@ -111,12 +129,14 @@ Sort files before they are passed to `generate`. [more details](#hooks-options)
Type: `function`<br>
Default: `(seed, files) => files.reduce((manifest, {name, path}) => ({...manifest, [name]: path}), seed)`

All entries in `files` correspond to the object structure described in the `Hooks Options` section.
All entries in `files` correspond to the object structure described in the `emit Hook Options` section.

Create the manifest. It can return anything as long as it's serialisable by `JSON.stringify`. [more details](#hooks-options)

**Use-case**: topological sort ([example](https://github.com/danethurber/webpack-manifest-plugin/pull/93))


## Hooks Options
## `emit` Hook Options

`filter`, `map`, `sort` takes as an input an Object with the following properties:

Expand Down Expand Up @@ -158,6 +178,24 @@ Type: `Boolean`

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

## `webpack-manifest-plugin-after-emit` Hook

Hook allows other plugins to use the manifest.
Look at [patch](https://github.com/danethurber/webpack-manifest-plugin/pull/76) and [spec](https://github.com/danethurber/webpack-manifest-plugin/blob/34257bc2da17c6f18ab64c4db938993d6143be47/spec/plugin.integration.spec.js#L68) for more details.

There are some arguments:

### `manifest`

Type: `Object`

Generated manifest.

### `next`

Type: `Function`

Callback that is for continuing execution flow.

## License

Expand Down