Skip to content

Commit 155a637

Browse files
committed
Merge remote-tracking branch 'origin/cn' into cn
2 parents 75e4ad1 + 180eeec commit 155a637

File tree

7 files changed

+116
-123
lines changed

7 files changed

+116
-123
lines changed

content/guides/hmr-react.md

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ npm install --save [email protected] [email protected]
3838
{
3939
"presets": [
4040
["es2015", {"modules": false}],
41-
// webpack understands the native import syntax, and uses it for tree shaking
41+
// webpack现在已经支持原生的import语句了, 并且将其运用在tree-shaking特性上
4242

4343
"stage-2",
44-
// Specifies what level of language features to activate.
45-
// Stage 2 is "draft", 4 is finished, 0 is strawman.
46-
// See https://tc39.github.io/process-document/
44+
// 规定JS运用的语言规范层级
45+
// Stage 2 是 "草案", 4 是 "已完成", 0 is "稻草人(strawman)"。
46+
// 详情查看 https://tc39.github.io/process-document/
4747

4848
"react"
49-
// Transpile React components to JavaScript
49+
// 转译React组件为JS代码
5050
],
5151
"plugins": [
5252
"react-hot-loader/babel"
53-
// Enables React code to work with HMR.
53+
// 开启react代码的模块热替换(HMR
5454
]
5555
}
5656
```
@@ -66,27 +66,28 @@ const webpack = require('webpack');
6666
module.exports = {
6767
entry: [
6868
'react-hot-loader/patch',
69-
// activate HMR for React
69+
// 开启react代码的模块热替换(HMR
7070

7171
'webpack-dev-server/client?http://localhost:8080',
72-
// bundle the client for webpack-dev-server
73-
// and connect to the provided endpoint
72+
// 为webpack-dev-server的环境打包好运行代码
73+
// 然后连接到指定服务器域名与端口
7474

7575
'webpack/hot/only-dev-server',
76-
// bundle the client for hot reloading
77-
// only- means to only hot reload for successful updates
76+
// 为热替换(HMR)打包好运行代码
77+
// only- 意味着只有成功更新运行代码才会执行热替换(HMR)
7878

7979

8080
'./index.js'
81-
// the entry point of our app
81+
// 我们app的入口文件
8282
],
8383
output: {
8484
filename: 'bundle.js',
85-
// the output bundle
85+
// 输出的打包文件
8686

8787
path: resolve(__dirname, 'dist'),
8888

8989
publicPath: '/'
90+
// 对于热替换(HMR)是必须的,让webpack知道在哪里载入热更新的模块(chunk)
9091
// necessary for HMR to know where to load the hot update chunks
9192
},
9293

@@ -96,13 +97,13 @@ module.exports = {
9697

9798
devServer: {
9899
hot: true,
99-
// enable HMR on the server
100+
// 开启服务器的模块热替换(HMR
100101

101102
contentBase: resolve(__dirname, 'dist'),
102-
// match the output path
103+
// 输出文件的路径
103104

104105
publicPath: '/'
105-
// match the output `publicPath`
106+
// 和上文output的"publicPath"值保持一致
106107
},
107108

108109
module: {
@@ -127,15 +128,16 @@ module.exports = {
127128

128129
plugins: [
129130
new webpack.HotModuleReplacementPlugin(),
130-
// enable HMR globally
131+
// 开启全局的模块热替换(HMR
131132

132133
new webpack.NamedModulesPlugin(),
134+
// 当模块热替换(HMR)时在浏览器控制台输出对用户更友好的模块名字信息
133135
// prints more readable module names in the browser console on HMR updates
134136
],
135137
};
136138
```
137139

138-
上面的内容涵盖了 webpack 配置的方方面面,并不是全部都和 HMR 相关。这个 webpack 开发服务器的[完整的文档](https://webpack.github.io/docs/webpack-dev-server.html)能够让你对它了解更多,这些在 webpack.js.org 上的[文章](https://webpack.js.org/concepts/)也应该一读。
140+
上面的内容涵盖了 webpack 配置的方方面面,并不是全部都和 HMR 相关。这个 webpack 开发服务器的[完整的文档](https://webpack.github.io/docs/webpack-dev-server.html)能够让你对它了解更多,这些在 webpack.js.org 上的[文章](https://doc.webpack-china.org/concepts/)也应该一读。
139141

140142
这里有一个基本假设,便是你的 JavaScript 入口在 `./src/index.js`,还有,你在使用 CSS 模块。
141143

@@ -173,7 +175,7 @@ const render = (Component) => {
173175

174176
render(App);
175177

176-
// Hot Module Replacement API
178+
// 模块热替换的 API
177179
if (module.hot) {
178180
module.hot.accept('./components/App', () => {
179181
render(App)
@@ -211,23 +213,25 @@ export default App;
211213

212214
2. 因此,我们可以使用 `module.hot` 钩子函数为特定资源启用 HMR(这里是`App.js`)。这里最重要的 API 是 `module.hot.accept`,它指定如何处理对特定依赖的更改。
213215

214-
3. 注意,因为 webpack 2 对 ES2015 模块有内置的支持,你不需要在 `module.hot.accept` 中重新引入你的根组件。要完成这项工作,你需要更改 Babel ES2015 在 `.babelrc` 的预设
216+
3. 注意,因为 webpack 2 对 ES2015 模块有内置的支持,你不需要在 `module.hot.accept` 中重新引入你的根组件。要完成这项工作,你需要更改 Babel ES2015 在 `.babelrc` 的预设值
215217

216218
```
217219
["es2015", {"modules": false}]
218220
```
219221

220-
like what we did in [Babel Config](#babel-config). Note that disabling Babel's module plugin is not only necessary for HMR. If you don't disable it you'll run into many other issues (see [Migrating from v1 to v2](/guides/migrating/#mixing-es2015-with-amd-and-commonjs) and [webpack-tree-shaking](http://www.2ality.com/2015/12/webpack-tree-shaking.html)).
222+
与我们在 [Babel 配置文件](#babel-config) 中所配置的是一样的。注意,不仅仅只有模块热替换的场景需要禁用Babel模块插件。如果你不将此插件禁用,你可能会遇到许多其他的问题(查看 [从webpack v1 迁移到 v2](/guides/migrating/#mixing-es2015-with-amd-and-commonjs) [webpack-tree-shaking](http://www.2ality.com/2015/12/webpack-tree-shaking.html))
221223

222-
4. Note that if you're using ES6 modules in your webpack 2 configuration file, and you change your `.babelrc` file in #3 above, you either need to use `require` or create two `.babelrc` files (issue [here](https://github.com/webpack/webpack.js.org/issues/154)):
223-
* One in the project root directory with `"presets": ["es2015"]
224-
* One in the home directory for webpack to build. For this example, in `src/`.
224+
4. 注意,如果你在webpack 2 配置文件中启用了ES6模块,并且按照上文#3 的配置,修改了你的`.babelrc` 文件,你需要使用`require`命令,或者,创建两个`.babelrc`文件(查看问题 [这里](https://github.com/webpack/webpack.js.org/issues/154)):
225+
* 一个文件放置在项目的根目录,并且加上配置: `"presets": ["es2015"]`
226+
* 另一个文件放置在webpack要构建代码的主目录。在这个例子里,放置的目录路径是`src/`
227+
228+
所以,在这种情景下,当 `src/components/App.js` 或者它的依赖文件被更改了, `module.hot.accept` 将会触发 `render` 方法,这意味着,因为 `App.js` 里面包含了对 `App.css` 的引用, 所以 `render` 方法同样会在 `App.css` 被修改的时候触发,
225229

226-
So in this case, `module.hot.accept` will fire the `render` method whenever `src/components/App.js` or its dependencies are changed - which means the `render` method will also fire when the `App.css` is changed, since `App.css` is included in `App.js`.
227230

228231
### index.html
229232

230-
This needs to be placed inside of `dist` in your project root. webpack-dev-server will not run without it.
233+
这个文件需要放置在你的项目根路径下的 `dist`目录,不然 webpack-dev-server 将因为缺少这个文件而无法运行。
234+
231235

232236
```html
233237
<!DOCTYPE html>

content/plugins/extract-text-webpack-plugin.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ title: extract-text-webpack-plugin
44

55
# extract text plugin for webpack 2
66

7-
API 从版本1起已经改变。用于 webpack 1 的版本,请看[the README in the webpack-1 branch](https://github.com/webpack/extract-text-webpack-plugin/blob/webpack-1/README.md)
7+
和 webpack 1 版本相比 API 已经发生改变。对于 webpack 1 版本,请查看 [webpack-1 分支的 README 文档](https://github.com/webpack/extract-text-webpack-plugin/blob/webpack-1/README.md)
88

99
## 安装
1010

11-
> 你可以用 [npm](https://nodejs.org/en/) 或者 [yarn](https://yarnpkg.com/)安装它
11+
> 可以使用 [npm](https://nodejs.org/en/) 或者 [yarn](https://yarnpkg.com/) 来安装
1212
1313
```sh
1414
npm install --save-dev extract-text-webpack-plugin
@@ -18,7 +18,7 @@ or
1818
yarn add --dev extract-text-webpack-plugin
1919
```
2020

21-
## css的使用例子
21+
## CSS 的用法示例
2222

2323
``` javascript
2424
var ExtractTextPlugin = require("extract-text-webpack-plugin");
@@ -37,56 +37,56 @@ module.exports = {
3737
}
3838
```
3939

40-
它会将所有的 入口chunk (entry chunks) 中的 `require("style.css")` 移动到分开的 css 文件。因此,你的样式不再内联到 javascript 里面,但会放到一个单独的 css 包文件 (`styles.css`)当中。 如果你的样式文件大小较大,这会更快,因为样式文件会跟 javascript 包并行加载
40+
它会将每个「入口 chunk(entry chunks)中的 `require("style.css")` 移动到分离的 css 输出文件中。所以,你的样式不再内联到 javascript 里面,而是分离到 css bundle(`styles.css`) 文件中。如果样式总量很大,加载就会变得很快,因为样式 bundle 会并行加载到 javascript bundle 中
4141

42-
优点:
42+
优势:
4343

44-
* 更少 style 标签 (旧版本的 IE 浏览器有限制)
45-
* CSS SourceMap (使用 `devtool: "source-map"``css-loader?sourceMap` 配置)
44+
* 更少的 style 标签旧版本的 IE 浏览器对 style 标签数量有限制)
45+
* CSS SourceMap使用 `devtool: "source-map"``css-loader?sourceMap` 配置
4646
* CSS 请求并行
4747
* CSS 单独缓存
48-
* 更快的浏览器运行时 (更少代码和 DOM 的运行)
48+
* 更快的浏览器运行时(runtime)(减少代码和减少 DOM 操作)
4949

50-
警告:
50+
警告
5151

5252
* 额外的 HTTP 请求
5353
* 更长的编译时间
5454
* 更复杂的配置
55-
* 没有运行时的公共路径修改
56-
* 没有热替换
55+
* 没有运行时(runtime)的公共路径修改
56+
* 没有模块热替换
5757

5858
## API
5959

6060
``` javascript
6161
new ExtractTextPlugin(options: filename | object)
6262
```
6363

64-
* `options.filename: string` _(必填)_ 生成文件的文件名。会包含 `[name]`, `[id]``[contenthash]`
64+
* `options.filename: string` _(必选)_ 生成文件的文件名。可能包含 `[name]`, `[id]``[contenthash]`
6565
* `[name]` chunk 的名称
6666
* `[id]` chunk 的数量
67-
* `[contenthash]` 根据提取文件内容的哈希值
68-
* `options.allChunks: boolean` 向所有额外的 chunk 提取(默认只提取初始加载模块
67+
* `[contenthash]` 提取文件内容的哈希值
68+
* `options.allChunks: boolean` 向所有额外的 chunk 中提取(默认情况下,只从初始chunk 提取
6969
* `options.disable: boolean` 禁用插件
70-
* `options.id: string` 此插件实例的唯一id。 (仅限高级用途,默认情况下自动生成)
70+
* `options.id: string` 此插件实例的唯一 id。(仅限于高级用法,默认情况下自动生成)
7171

72-
The `ExtractTextPlugin` 每个 入口chunk 都会生成一个文件,所以当你使用多个 入口chunk 的时候,你必须使用 `[name]`, `[id]` 或者 `[contenthash]`.
72+
`ExtractTextPlugin` 为每个入口 chunk 生成一个输出文件,所以在使用多个入口时,你必须使用 `[name]`, `[id]` 或者 `[contenthash]`
7373

7474
``` javascript
7575
ExtractTextPlugin.extract(options: loader | object)
7676
```
7777

78-
从已经有的加载器里创建一个提取的加载器,支持加载器类似,`{ loader: string; query: object }`
78+
从已有的 loader 中创建一个用于提取的 loader,支持的 loader `{ loader: string; query: object }` 这种类型
7979

80-
* `options.loader: string | object | loader[]` _(必填)_ 加载器应用于将资源转换成 css 输出模块。
81-
* `options.fallbackLoader: string | object | loader[]` 加载器应用于当 css 没有被提取(也就是一个额外的 chunk,当 `allChunks: false`)
82-
* `options.publicPath: string` 对加载器的 `publicPath` 配置重写
80+
* `options.loader: string | object | loader[]` _(必选)_loader 用于将资源转换为 css 导出模块
81+
* `options.fallbackLoader: string | object | loader[]` loader 用于在 css 没有被提取时(例如,在 `allChunks: false` 时的额外的 chunk)
82+
* `options.publicPath: string` 重写 loader 的 `publicPath` 设置
8383

84-
这也是一个 提取函数的实例。如果你有多于一个 `ExtractTextPlugin` 插件 你应使用这种办法
84+
在 extract 实例还有一个 extract 函数。如果有多个 `ExtractTextPlugin` 实例,你应该使用此方法
8585

8686
```javascript
8787
let ExtractTextPlugin = require('extract-text-webpack-plugin');
8888

89-
// 多个提取实例
89+
// 多个 extract 实例
9090
let extractCSS = new ExtractTextPlugin('stylesheets/[name].css');
9191
let extractLESS = new ExtractTextPlugin('stylesheets/[name].less');
9292

content/plugins/index.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ contributors:
44
- simon04
55
---
66

7-
webpack has a rich plugin interface. Most of the features within webpack itself use this plugin interface. This makes webpack **flexible**.
7+
webpack 有着大量的插件接口(plugin interface)。多数功能由 webpack 自己的插件接口提供。这些插件使 webpack 变得**极其灵活**
88

9-
|Name|Description|
9+
10+
|名称|描述|
1011
|:--:|:----------|
11-
|[commons-chunk-plugin](/plugins/commons-chunk-plugin)|Generates chunks of common modules shared between entry points and splits them into separate bundles, e.g., `1vendor.bundle.js` && `app.bundle.js`|
12-
|[extract-text-webpack-plugin](/plugins/extract-text-webpack-plugin)|Extracts Text (CSS) from your bundles into a separate file (app.bundle.css)|
13-
|[component-webpack-plugin](/plugins/component-webpack-plugin)|Use components with webpack|
14-
|[compression-webpack-plugin](/plugins/compression-webpack-plugin)|Prepare compressed versions of assets to serve them with Content-Encoding|
15-
|[i18n-webpack-plugin](/plugins/i18n-webpack-plugin)|Adds i18n support to your bundles|
16-
|[html-webpack-plugin](/plugins/html-webpack-plugin)| Simplifies creation of HTML files (`index.html`) to serve your bundles|
12+
|[commons-chunk-plugin](/plugins/commons-chunk-plugin)|将多个入口起点之间共享的公共模块,生成为一些 chunk,并且分离到单独的 bundle 中,例如,`1vendor.bundle.js` `app.bundle.js`|
13+
|[extract-text-webpack-plugin](/plugins/extract-text-webpack-plugin)|从 bundle 中提取文本(CSS)到分离的文件(app.bundle.css|
14+
|[component-webpack-plugin](/plugins/component-webpack-plugin)|通过 webpack 中使用组件|
15+
|[compression-webpack-plugin](/plugins/compression-webpack-plugin)|预先准备的资源压缩版本,使用 Content-Encoding 提供访问服务|
16+
|[i18n-webpack-plugin](/plugins/i18n-webpack-plugin)|为 bundle 增加国际化支持|
17+
|[html-webpack-plugin](/plugins/html-webpack-plugin)| 用于简化 HTML 文件(`index.html`)的创建,提供访问 bundle 的服务。|
1718

1819
***
1920

content/plugins/source-map-dev-tool-plugin.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ contributors:
66

77
?> Review this content
88

9-
Adds SourceMaps for assets.
9+
给资源添加 SourceMap。
1010

1111
```javascript
1212
new webpack.SourceMapDevToolPlugin(options)
1313
```
1414

15-
* `options.test` / `options.include` / `options.exclude` (`string|RegExp|Array`): Used to determine which assets should be processed. Each one can be a `RegExp` (asset filename is matched), a `string` (asset filename need to start with this string) or an `Array` of those (any of them need to be matched). `test` defaults to `.js` files if omitted.
16-
* `options.filename` (`string`): defines the output filename of the SourceMap. If no value is provided the SourceMap is inlined.
17-
* `options.append` (`string`): is appended to the original asset. Usually the `#sourceMappingURL` comment. `[url]` is replaced with a URL to the SourceMap file. `false` disables the appending.
18-
* `options.moduleFilenameTemplate` / `options.fallbackModuleFilenameTemplate` (`string`): see `output.devtoolModuleFilenameTemplate`.
19-
* `options.module` (`boolean`): (defaults to `true`) When `false` loaders do not generate SourceMaps and the transformed code is used as source instead.
20-
* `options.columns` (`boolean`): (defaults to `true`) When `false` column mappings in SourceMaps are ignored and a faster SourceMap implementation is used.
21-
* `options.lineToLine` (`{test: string|RegExp|Array, include: string|RegExp|Array, exclude: string|RegExp|Array}` matched modules uses simple (faster) line to line source mappings.
15+
* `options.test` / `options.include` / `options.exclude` (`string|RegExp|Array`): 用来规定哪些资源应该被处理。可以是 `RegExp`(匹配资源文件名),也可以是 `string`(资源文件名的开头)或者包含以上两种的 `Array`(需要匹配其中一个),`test` 如果没有设置,默认为 `.js` 文件。
16+
* `options.filename` (`string`): 定义 SourceMap 输出的文件名。如果不设置,SourceMap 会放在代码文件里。
17+
* `options.append` (`string`): 添加到原始资源之后。通常是 `#sourceMappingURL` 注释。`[url]`会被替换成 SourceMap 文件的路径。`false` 禁用添加。
18+
* `options.moduleFilenameTemplate` / `options.fallbackModuleFilenameTemplate` (`string`): 查看 `output.devtoolModuleFilenameTemplate`
19+
* `options.module` (`boolean`): (默认为 `true`) `false` loaders 不产生 SourceMaps 时,将转换后的代码作为源.
20+
* `options.columns` (`boolean`): (默认为 `true`) 当 SourceMaps 里的 `false` column 映射 (mappings) 被忽略时,会使用一个更快的 SourceMap 实现。
21+
* `options.lineToLine` (`{test: string|RegExp|Array, include: string|RegExp|Array, exclude: string|RegExp|Array}` 使用简单(快速)的「行到行资源映射(line to line source mappings)」来匹配模块。
2222

2323
## Examples
2424

0 commit comments

Comments
 (0)