Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
dear-lizhihua committed Aug 6, 2017
2 parents f0754ef + bdf4dbb commit 34bc9e3
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 77 deletions.
2 changes: 1 addition & 1 deletion content/configuration/dev-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ Enable webpack's Hot Module Replacement feature:
hot: true
```

T> Note that you must also include a `new webpack.HotModuleReplacementPlugin()` to fully enable HMR. See the [HMR concepts page](/concepts/hot-module-replacement) for more information.
T> Note that `webpack.HotModuleReplacementPlugin` is required to fully enable HMR. If `webpack` or `webpack-dev-server` are launched with the `--hot` option, this plugin will be added automatically, so you may not need to add this to your `webpack.config.js`. See the [HMR concepts page](/concepts/hot-module-replacement) for more information.


## `devServer.hotOnly`
Expand Down
2 changes: 1 addition & 1 deletion content/configuration/externals.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $('.my-element').animate(...);

The bundle with external dependencies can be used in various module contexts, such as [CommonJS, AMD, global and ES2015 modules](/concepts/modules). The external library may be available in any of these forms:

* __global__ - An external library can be available as a global variable. The consumer can achieve this by including the external library in a script tag. This is the default setting for externals.
* __root__ - An external library can be available as a global variable. The consumer can achieve this by including the external library in a script tag. This is the default setting for externals.
* __commonjs__ - The consumer application may be using a CommonJS module system and hence the external library should be available as a CommonJS module.
* __commonjs2__ - Similar to the above line but where the export is `module.exports.default`.
* __amd__ - Similar to the above line but using AMD module system.
Expand Down
7 changes: 6 additions & 1 deletion content/configuration/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ W> `Rule.query` is deprecated in favor of `Rule.options` and `UseEntry.options`.

An object with parser options. All applied parser options are merged.

For each different parser options object a new parser is created and plugins can apply plugins depending on the parser options. Many of the default plugins apply their parser plugins only if a property in the parser options is not set or true.
Parsers may inspect these options and disable or reconfigure themselves accordingly. Most of the default plugins interpret the values as follows:

* Setting the option to `false` disables the parser.
* Setting the option to `true` or leaving it `undefined` enables the parser.

However, parser plugins may accept more than just a boolean. For example, the internal `NodeStuffPlugin` can accept an object instead of `true` to add additional options for a particular Rule.

**Examples** (parser options by the default plugins):

Expand Down
19 changes: 14 additions & 5 deletions content/configuration/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ contributors:
- sokra
- skipjack
- oneforwonder
- Rob--W
---

These options configure whether to polyfill or mock certain [Node.js globals](https://nodejs.org/docs/latest/api/globals.html) and modules. This allows code originally written for the Node.js environment to run in other environments like the browser. This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/master/lib/NodeStuffPlugin.js).
These options configure whether to polyfill or mock certain [Node.js globals](https://nodejs.org/docs/latest/api/globals.html) and modules. This allows code originally written for the Node.js environment to run in other environments like the browser.

This feature is provided by webpack's internal [`NodeStuffPlugin`](https://github.com/webpack/webpack/blob/master/lib/NodeStuffPlugin.js) plugin. If the target is "web" (default) or "webworker", the [`NodeSourcePlugin`](https://github.com/webpack/webpack/blob/master/lib/node/NodeSourcePlugin.js) plugin is also activated.


## `node`
Expand All @@ -19,7 +22,7 @@ This is an object where each property is the name of a Node global or module and
- `true`: Provide a polyfill.
- `"mock"`: Provide a mock that implements the expected interface but has little or no functionality.
- `"empty"`: Provide an empty object.
- `false`: Provide nothing. Code that expects this object to be defined may crash.
- `false`: Provide nothing. Code that expects this object may crash with a `ReferenceError`. Code that attempts to import the module using `require('modulename')` may trigger a `Cannot find module "modulename"` error.

W> Not every Node global supports all four options. The compiler will throw an error for property-value combinations that aren't supported (e.g. `process: 'empty'`). See the sections below for more details.

Expand All @@ -34,10 +37,12 @@ node: {
__dirname: "mock",
Buffer: true,
setImmediate: true

// See "Other node core libraries" for additional options.
}
```

Since webpack 3.0.0, the `node` option may be set to `false` to turn off the `NodeSourcePlugin` completely.
Since webpack 3.0.0, the `node` option may be set to `false` to completely turn off the `NodeStuffPlugin` and `NodeSourcePlugin` plugins.


## `node.console`
Expand Down Expand Up @@ -109,9 +114,13 @@ Default: `true`

`boolean | "mock" | "empty"`

Many other Node.js core libraries can be configured as well. See the list of [Node.js core libraries and their polyfills](https://github.com/webpack/node-libs-browser).
W> This option is only activated (via `NodeSourcePlugin`) when the target is unspecified, "web" or "webworker".

Polyfills for Node.js core libraries from [`node-libs-browser`](https://github.com/webpack/node-libs-browser) are used if available, when the `NodeSourcePlugin` plugin is enabled. See the list of [Node.js core libraries and their polyfills](https://github.com/webpack/node-libs-browser#readme).

By default, webpack will polyfill each library if there is a known polyfill or do nothing if there is not one. In the latter case, webpack will behave as if the module name was configured with the `false` value.

By default, Webpack will polyfill each library if there is a known polyfill or do nothing if there is not one.
T> To import a built-in module, use [`__non_webpack_require__`](/api/module-variables/#__non_webpack_require__-webpack-specific-), i.e. `__non_webpack_require__('modulename')` instead of `require('modulename')`.

Example:

Expand Down
9 changes: 6 additions & 3 deletions content/configuration/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ The following substitutions are available in template strings (via webpack's int
| [chunkhash] | The hash of the chunk content |
| [name] | The module name |
| [id] | The module identifier |
| [file] | The module filename |
| [filebase] | The module [basename](https://nodejs.org/api/path.html#path_path_basename_path_ext) |
| [query] | The module query, i.e., the string following `?` in the filename |

The lengths of `[hash]` and `[chunkhash]` can be specified using `[hash:16]` (defaults to 20). Alternatively, specify [`output.hashDigestLength`](#output-hashdigestlength) to configure the length globally.
Expand Down Expand Up @@ -617,7 +615,12 @@ This option is only used when [`devtool`](/configuration/devtool) uses a SourceM

Configure how source maps are named. By default `"[file].map"` is used.

Technically, the `[name]`, `[id]`, `[hash]` and `[chunkhash]` [placeholders](#output-filename) can be used, if generating a SourceMap for chunks. In addition to that, the `[file]` placeholder is replaced with the filename of the original file. It's recommended to only use the `[file]` placeholder, as the other placeholders won't work when generating SourceMaps for non-chunk files. Best leave the default.
The `[name]`, `[id]`, `[hash]` and `[chunkhash]` substitions from [#output-filename](#output-filename) can be used. In addition to those, you can use substitutions listed below. The `[file]` placeholder is replaced with the filename of the original file. We recommend __only using the `[file]` placeholder__, as the other placeholders won't work when generating SourceMaps for non-chunk files.

| Template | Description |
| -------------------------- | ----------------------------------------------------------------------------------- |
| [file] | The module filename |
| [filebase] | The module [basename](https://nodejs.org/api/path.html#path_path_basename_path_ext) |


## `output.sourcePrefix`
Expand Down
4 changes: 0 additions & 4 deletions content/development/plugin-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ module.exports = MyPlugin;
```

- `compilation.modules`: An array of modules (built inputs) in the compilation. Each module manages the build of a raw file from your source library.

- `module.fileDependencies`: An array of source file paths included into a module. This includes the source JavaScript file itself (ex: `index.js`), and all dependency asset files (stylesheets, images, etc) that it has required. Reviewing dependencies is useful for seeing what source files belong to a module.

- `compilation.chunks`: An array of chunks (build outputs) in the compilation. Each chunk manages the composition of a final rendered assets.

- `chunk.modules`: An array of modules that are included into a chunk. By extension, you may look through each module's dependencies to see what raw source files fed into a chunk.

- `chunk.files`: An array of output filenames generated by the chunk. You may access these asset sources from the `compilation.assets` table.

### Monitoring the watch graph
Expand Down
3 changes: 2 additions & 1 deletion content/guides/code-splitting.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contributors:
- TheDutchCoder
- rouzbeh84
- shaodahong
- sudarsangp
---

T> This guide extends the examples provided in [Getting Started](/guides/getting-started) and [Managing Built Files](/guides/output-management). Please make sure you are at least familiar with the examples provided in them.
Expand Down Expand Up @@ -203,7 +204,7 @@ __webpack.config.js__
};
```

We'll also update our project to remove the now unused files:
Note the use of `chunkFilename`, which determines the name of non-entry chunk files. For more information on `chunkFilename`, see [output documentation](/configuration/output/#output-chunkfilename). We'll also update our project to remove the now unused files:

__project__

Expand Down
4 changes: 2 additions & 2 deletions content/plugins/context-replacement-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ title: ContextReplacementPlugin
contributors:
- simon04
related:
- title: Issue #2783 - ContextReplacementPlugin Description
- url: https://github.com/webpack/webpack/issues/2783#issuecomment-234137265
- title: Issue 2783 - ContextReplacementPlugin Description
url: https://github.com/webpack/webpack/issues/2783#issuecomment-234137265
---

*Context* refers to a [require with an expression](/guides/dependency-management/#require-with-expression) such as `require('./locale/' + name + '.json')`. When encountering such an expression, webpack infers the directory (`'./locale/'`) and a regular expression (`/^.*\.json$/`). Since the `name` is not known at compile time, webpack includes every file as module in the bundle.
Expand Down
1 change: 0 additions & 1 deletion styles/markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@

p {
code, tt {
display: inline-block;
max-width: 100%;
line-height: initial;
overflow: auto;
Expand Down
Loading

0 comments on commit 34bc9e3

Please sign in to comment.