Skip to content

docs(plugins): add hashed-module-ids-plugin.md and named-modules-plugin.md #1392

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

Merged
merged 15 commits into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions content/guides/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ A sample output when using `WebpackManifestPlugin` in our config looks like:
## Deterministic hashes

To minimize the size of generated files, webpack uses identifiers instead of module names. During compilation, identifiers are generated, mapped to chunk filenames and then put into a JavaScript object called *chunk manifest*.
To generate identifiers that are preserved over builds, webpack supplies the `NamedModulesPlugin` (recommended for development) and `HashedModuleIdsPlugin` (recommended for production).

?> When exist, link to `NamedModulesPlugin` and `HashedModuleIdsPlugin` docs pages
To generate identifiers that are preserved over builds, webpack supplies the [`NamedModulesPlugin`](/plugins/named-modules-plugin) (recommended for development) and [`HashedModuleIdsPlugin`](/plugins/hashed-module-ids-plugin) (recommended for production).

?> Describe how the option `recordsPath` option works

Expand Down
4 changes: 2 additions & 2 deletions content/plugins/commons-chunk-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ new webpack.optimize.CommonsChunkPlugin({
<script src="app.js" charset="utf-8"></script>
```

Hint: In combination with long term caching you may need to use the [`ChunkManifestWebpackPlugin`](https://github.com/diurnalist/chunk-manifest-webpack-plugin) to avoid that the vendor chunk changes. You should also use records to ensure stable module ids.
T> In combination with long term caching you may need to use the [`ChunkManifestWebpackPlugin`](https://github.com/diurnalist/chunk-manifest-webpack-plugin) to avoid the vendor chunk changes. You should also use records to ensure stable module ids, e.g. using [`NamedModulesPlugin`](/plugins/named-modules-plugin) or [`HashedModuleIdsPlugin`](/plugins/hashed-module-ids-plugin).


### Move common modules into the parent chunk

With [Code Splitting](/guides/code-splitting) multiple child chunks of an entry chunk can have common dependencies. To prevent duplication these can be moved into the parent. This reduces overall size, but does have a negative effect on the initial load time. If it is expected that users will need to download many sibling chunks, i.e. children of the entry chunk, then this should improve load time overall.
With [Code Splitting](/guides/code-splitting), multiple child chunks of an entry chunk can have common dependencies. To prevent duplication these can be moved into the parent. This reduces overall size, but does have a negative effect on the initial load time. If it is expected that users will need to download many sibling chunks, i.e. children of the entry chunk, then this should improve load time overall.

```javascript
new webpack.optimize.CommonsChunkPlugin({
Expand Down
35 changes: 35 additions & 0 deletions content/plugins/hashed-module-ids-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: HashedModuleIdsPlugin
contributors:
- shaodahong
---

This plugin will cause hashes to be based on the relative path of the module, generating a four character string as the module id. Suggested for use in production.

``` js
new webpack.HashedModuleIdsPlugin({
// Options...
})
```


## Options

This plugin supports the following options:

- `hashFunction`: The hashing algorithm to use, defaults to `'md5'`. All functions from Node.JS' [`crypto.createHash`](https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm) are supported.
- `hashDigest`: The encoding to use when generating the hash, defaults to `'base64'`. All encodings from Node.JS' [`hash.digest`](https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding) are supported.
- `hashDigestLength`: The prefix length of the hash digest to use, defaults to `4`.


## Usage

Here's an example of how this plugin might be used:

``` js
new webpack.HashedModuleIdsPlugin({
hashFunction: 'sha256',
hashDigest: 'hex',
hashDigestLength: 20
})
```
11 changes: 11 additions & 0 deletions content/plugins/named-modules-plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: NamedModulesPlugin
contributors:
- shaodahong
---

This plugin will cause the relative path of the module to be displayed when [HMR](/guides/hot-module-replacement) is enabled. Suggested for use in development.

``` js
new webpack.NamedModulesPlugin()
```