Skip to content

Commit 712f7ab

Browse files
committed
Merge remote-tracking branch 'upstream/cn' into cn
2 parents a1efa41 + d6724e2 commit 712f7ab

File tree

7 files changed

+91
-96
lines changed

7 files changed

+91
-96
lines changed

content/guides/code-splitting-require.md

100644100755
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ contributors:
66
- rahulcs
77
---
88

9-
In this section, we will discuss how webpack splits code using `require.ensure()`.
9+
在这一节,我们会讨论 webpack 如何使用 `require.ensure()` 进行代码拆分。
1010

1111
## `require.ensure()`
1212

13-
webpack statically parses for `require.ensure()` in the code while building and adds the modules here into a separate chunk. This new chunk is loaded on demand by webpack through jsonp.
13+
webpack 在编译时,会静态地解析代码中的 `require.ensure()`,同时将模块添加到一个分开的 chunk 当中。这个新的 chunk 会被 webpack 通过 `jsonp` 来按需加载。
1414

15-
The syntax is as follows
15+
语法如下:
1616

1717
```javascript
1818
require.ensure(dependencies: String[], callback: function(require), chunkName: String)
1919
```
2020

21-
#### dependencies
22-
This is an array of strings where we can declare all the modules that need to be made available before all the code in the callback function can be executed.
21+
#### 依赖 dependencies
22+
这是一个字符串数组,通过这个参数,在所有的回调函数的代码被执行前,我们可以将所有需要用到的模块进行声明。
2323

24-
#### callback
25-
This is the callback function that webpack will execute once the dependencies are loaded. An implementation of the require object is sent as a parameter to this function. This is so that, we can further `require()` the dependencies and any other modules for execution.
24+
#### 回调 callback
25+
当所有的依赖都加载完成后,webpack会执行这个回调函数。`require` 对象的一个实现会作为一个参数传递给这个回调函数。因此,我们可以进一步 `require()` 依赖和其它模块提供下一步的执行。
2626

27-
#### chunkName
28-
The chunkName is the name given to the chunk created by this particular `require.ensure()`. By giving the same name at different split points of `require.ensure()`, we can make sure all the dependencies are collectively put in the same bundle.
27+
#### chunk名称 chunkName
28+
chunkName 是提供给这个特定的 `require.ensure()` 的 chunk 的名称。通过提供 `require.ensure()` 不同执行点相同的名称,我们可以保证所有的依赖都会一起放进相同的 文件束(bundle)。
2929

30-
Let us consider the following project
30+
让我们来看以下的项目
3131

3232
```bash
3333
\\ file structure
@@ -69,36 +69,37 @@ module.exports = function(env) {
6969
}
7070
}
7171
```
72-
On running webpack on this project, we find that webpack has created two new bundles, `bundle.js` and `0.bundle.js`.
72+
通过执行这个项目的 webpack 构建,我们发现 webpack 创建了2个新的文件束, `bundle.js` `0.bundle.js`
7373

74-
`entry.js` and `a.js` are bundled in `bundle.js`.
74+
`entry.js` `a.js` 被打包进 `bundle.js`.
7575

76-
`b.js` is bundled in `0.bundle.js`.
76+
`b.js` 被打包进 `0.bundle.js`.
7777

78-
?> `require.ensure` relies on `Promises` internally. If you use `require.ensure` with older browsers, remember to shim `Promise.` [es6-promise polyfill](https://github.com/stefanpenner/es6-promise).
78+
?> `require.ensure` 内部依赖于 `Promises`。 如果你在旧的浏览器中使用 `require.ensure` 请记得 去 shim `Promise.` [es6-promise polyfill](https://github.com/stefanpenner/es6-promise).
7979

80-
## Gotchas for `require.ensure()`
80+
## `require.ensure()` 的坑点
8181

82-
### Empty Array as Parameter
82+
### 空数组作为参数
8383

8484
```javascript
8585
require.ensure([], function(require){
8686
require('./a.js');
8787
});
8888
```
8989

90-
The above code ensures that a split point is created and `a.js` is bundled separately by webpack.
90+
以上代码保证了拆分点被创建,而且 `a.js` webpack 分开打包。
9191

92-
### Dependencies as Parameter
92+
### 依赖作为参数
9393

9494
```javascript
9595
require.ensure(['./a.js'], function(require) {
9696
require('./b.js');
9797
});
9898
```
9999

100-
In the above code, `a.js` and `b.js` are bundled together and split from the main bundle. But only the contents of `b.js` are executed. The contents of `a.js` are only made available and not executed.
101-
To execute `a.js`, we will have to require it in a sync manner like `require('./a.js')` for the JavaScript to get executed.
100+
上面代码, `a.js``b.js` 都被打包到一起,而且从主文件束中拆分出来。但只有 `b.js` 的内容被执行。`a.js` 的内容仅仅是可被使用,但并没有被输出。
101+
102+
想去执行 `a.js`,我们需要异步地引用它,如 `require('./a.js')`,让它的 JavaScritp 被执行。
102103

103104
***
104105

generated/loaders/bundle-loader.md

100644100755
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,37 @@ title: bundle-loader
33
source: https://raw.githubusercontent.com/webpack/bundle-loader/master/README.md
44
edit: https://github.com/webpack/bundle-loader/edit/master/README.md
55
---
6-
# bundle loader for webpack
6+
# webpack 的文件束加载器
77

88
## Usage
99

10-
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
10+
[文档: 使用加载器](http://webpack.github.io/docs/using-loaders.html)
1111

1212
``` javascript
13-
// The chunk is requested, when you require the bundle
13+
// 当你引用 文件束 (bundle) 的时候,chunk 会被浏览器加载。
1414
var waitForChunk = require("bundle-loader!./file.js");
1515

16-
// To wait until the chunk is available (and get the exports)
17-
// you need to async wait for it.
16+
// 为了等待 chunk 的加载完成 (而且为了拿到 exports 输出)
17+
// 你需要异步去等待它
1818
waitForChunk(function(file) {
19-
// use file like is was required with
19+
// 这里可以使用file,就像是用下面的代码require进来一样
2020
// var file = require("./file.js");
2121
});
22-
// wraps the require in a require.ensure block
22+
// require 包裹在 require.ensure 的代码块中
2323
```
2424

25-
The file is requested when you require the bundle loader. If you want it to request it lazy, use:
25+
当你引用文件束的时候,chunk 会被浏览器加载。如果你想它懒加载,请用:
2626

2727
``` javascript
2828
var load = require("bundle-loader?lazy!./file.js");
2929

30-
// The chunk is not requested until you call the load function
30+
// 文件束不会被加载,除非你调用了 call 函数
3131
load(function(file) {
3232

3333
});
3434
```
3535

36-
You may set name for bundle (`name` query parameter). See [documentation](https://github.com/webpack/loader-utils#interpolatename).
36+
你可能会给文件束设名称(`name` 查询参数)。请查看[documentation](https://github.com/webpack/loader-utils#interpolatename).
3737

3838
``` javascript
3939
require("bundle-loader?lazy&name=my-chunk!./file.js");

generated/loaders/html-loader.md

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ title: html-loader
33
source: https://raw.githubusercontent.com/webpack/html-loader/master/README.md
44
edit: https://github.com/webpack/html-loader/edit/master/README.md
55
---
6-
## Install
6+
## 安装
77

88
```bash
99
npm i -D html-loader
1010
```
1111

1212
## Usage
1313

14-
By default every local `<img src="image.png">` is required (`require('./image.png')`). You may need to specify loaders for images in your configuration (recommended `file-loader` or `url-loader`).
14+
默认情况下,每个本地的 `<img src="image.png">` 都需要通过 require (`require('./image.png')`)来进行加载。您可能需要在配置中为图片指定 loader(推荐 `file-loader` `url-loader`
1515

16-
You can specify which tag-attribute combination should be processed by this loader via the query parameter `attrs`. Pass an array or a space-separated list of `<tag>:<attribute>` combinations. (Default: `attrs=img:src`)
16+
您可以通过查询参数 `attrs`,来指定哪个标签属性组合(tag-attribute combination)应该被此 loader 处理。传递数组或以空格分隔的 `<tag>:<attribute>` 组合的列表。(默认值:`attrs=img:src`
1717

18-
To completely disable tag-attribute processing (for instance, if you're handling image loading on the client side) you can pass in `attrs=false`.
18+
要完全禁用对标签属性的处理(例如,如果你在客户端处理图片加载),你可以传入 `attrs=false`
1919

20-
## Examples
20+
## 示例
2121

22-
With this configuration:
22+
使用此配置:
2323

2424
```js
2525
{
@@ -67,14 +67,14 @@ require("html-loader?-attrs!./file.html");
6767
// => '<img src="image.jpg" data-src="image2x.png" >'
6868
```
6969

70-
minimized by running `webpack --optimize-minimize`
70+
通过运行 `webpack --optimize-minimize` 来最小化
7171

7272
```html
7373
'<img src=http://cdn.example.com/49eba9f/a9f92ca.jpg
7474
data-src=data:image/png;base64,...>'
7575
```
7676

77-
or specify the `minimize` query in your `webpack.conf.js`
77+
或者在 `webpack.conf.js` 中指定 `minimize` 查询参数
7878

7979
```js
8080
module: {
@@ -90,11 +90,9 @@ module: {
9090

9191
### 'Root-relative' URLs
9292

93-
For urls that start with a `/`, the default behavior is to not translate them.
94-
If a `root` query parameter is set, however, it will be prepended to the url
95-
and then translated.
93+
对于以 `/` 开头的 url,默认行为是不转换它们。如果设置了 `root` 查询参数,它将被添加到 URL 之前,然后进行转换。
9694

97-
With the same configuration as above:
95+
和上面配置相同:
9896

9997
``` html
10098
<!-- file.html -->
@@ -113,9 +111,9 @@ require("html-loader?root=.!./file.html");
113111
// => '<img src="http://cdn.example.com/49eba9f/a992ca.jpg">'
114112
```
115113

116-
### Interpolation
114+
### 插值
117115

118-
You can use `interpolate` flag to enable interpolation syntax for ES6 template strings, like so:
116+
您可以使用 `interpolate` 标记,为 ES6 模板字符串启用插值语法,就像这样:
119117

120118
```js
121119
require("html-loader?interpolate!./file.html");
@@ -126,7 +124,7 @@ require("html-loader?interpolate!./file.html");
126124

127125
<div>${require('./components/gallery.html')}</div>
128126
```
129-
And if you only want to use `require` in template and any other `${}` are not to be translated, you can set `interpolate` flag to `require`, like so:
127+
如果你只想在模板中使用 `require`,任何其它的 `${}` 不被转换,你可以设置 `interpolate` 标记为 `require`,就像这样:
130128

131129
```js
132130
require("html-loader?interpolate=require!./file.ftl");
@@ -143,17 +141,17 @@ require("html-loader?interpolate=require!./file.ftl");
143141
<div>${require('./components/gallery.html')}</div>
144142
```
145143

146-
### Export formats
144+
### 导出格式
147145

148-
There are different export formats available:
146+
这里有几种不同的可用导出格式:
149147

150-
+ ```module.exports``` (default, cjs format). "Hello world" becomes ```module.exports = "Hello world";```
151-
+ ```exports.default``` (when ```exportAsDefault``` param is set, es6to5 format). "Hello world" becomes ```exports.default = "Hello world";```
152-
+ ```export default``` (when ```exportAsEs6Default``` param is set, es6 format). "Hello world" becomes ```export default "Hello world";```
148+
+ ```module.exports```(默认配置,cjs 格式)。"Hello world" 转为 ```module.exports = "Hello world";```
149+
+ ```exports.default``` (当设置了 ```exportAsDefault``` 参数,es6to5 格式)。"Hello world" 转为 ```exports.default = "Hello world";```
150+
+ ```export default``` (当设置了 ```exportAsEs6Default``` 参数,es6 格式)。"Hello world" 转为 ```export default "Hello world";```
153151

154-
### Advanced options
152+
### 高级选项
155153

156-
If you need to pass [more advanced options](https://github.com/webpack/html-loader/pull/46), especially those which cannot be stringified, you can also define an `htmlLoader`-property on your `webpack.config.js`:
154+
如果你需要传递[更多高级选项](https://github.com/webpack/html-loader/pull/46),特别是那些不能被字符串化,你还可以在 `webpack.config.js` 中定义一个 `htmlLoader` 属性:
157155

158156
```js
159157
var path = require('path')
@@ -176,7 +174,7 @@ module.exports = {
176174
};
177175
```
178176

179-
If you need to define two different loader configs, you can also change the config's property name via `html-loader?config=otherHtmlLoaderConfig`:
177+
如果你需要定义两个不同的 loader 配置,你也可以通过 `html-loader?config=otherHtmlLoaderConfig` 改变配置的属性名:
180178

181179
```js
182180
module.exports = {
@@ -195,20 +193,15 @@ module.exports = {
195193
};
196194
```
197195

198-
### Export into HTML files
196+
### 导出到 HTML 文件
199197

200-
A very common scenario is exporting the HTML into their own _.html_ file, to
201-
serve them directly instead of injecting with javascript. This can be achieved
202-
with a combination of 3 loaders:
198+
一个很常见的场景,将 HTML 导出到 _.html_ 文件中,直接访问它们,而不是使用 javascript 注入。这可以通过3个 loader 的组合来实现:
203199

204200
- [file-loader](https://github.com/webpack/file-loader)
205201
- [extract-loader](https://github.com/peerigon/extract-loader)
206202
- html-loader
207203

208-
The html-loader will parse the URLs, require the images and everything you
209-
expect. The extract loader will parse the javascript back into a proper html
210-
file, ensuring images are required and point to proper path, and the file loader
211-
will write the _.html_ file for you. Example:
204+
html-loader 将解析 URL,并请求图片和你所期望的一切资源。extract-loader 会将 javascript 解析为合适的 html 文件,确保引用的图片指向正确的路径,file-loader 将结果写入 .html 文件。示例:
212205

213206
```js
214207
{
@@ -217,7 +210,7 @@ will write the _.html_ file for you. Example:
217210
}
218211
```
219212

220-
## Maintainers
213+
## 维护人员
221214

222215
<table>
223216
<tbody>
@@ -309,4 +302,4 @@ SOFTWARE.
309302

310303
***
311304

312-
> 原文:https://webpack.js.org/loaders/html-loader/
305+
> 原文:https://webpack.js.org/loaders/html-loader/

generated/loaders/multi-loader.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ edit: https://github.com/webpack/multi-loader/edit/master/README.md
55
---
66
# multi-loader
77

8-
This loader requires a module multiple times, each time loaded with a different loader. Like in a multi entry point the exports of the last item are exported.
8+
这个loader多次需要一个模块,每次被加载一个不同的loader。像在多入口点中,导出最后一个loader的导出。
99

10-
A normal user probably don't need this loader, but it's useful in combination with other loaders.
10+
普通用户可能不需要这个loader,但它与其它loader结合使用还是很有用的。
1111

12-
Example:
12+
例:
1313

1414
``` javascript
1515
var multi = require("multi-loader");
@@ -37,4 +37,4 @@ MIT (http://www.opensource.org/licenses/mit-license.php)
3737

3838
***
3939

40-
> 原文:https://webpack.js.org/loaders/multi-loader/
40+
> 原文:https://webpack.js.org/loaders/multi-loader/

generated/loaders/react-proxy-loader.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@ edit: https://github.com/webpack/react-proxy-loader/edit/master/README.md
55
---
66
# react-proxy-loader
77

8-
Wraps a react component in a proxy component to enable Code Splitting (loads a react component and its dependencies on demand).
8+
在代理组件中封装react组件以启用代码拆分(加载一个react组件及其依赖需求)
99

10-
## installation
10+
## 安装
1111

1212
`npm install react-proxy-loader`
1313

14-
## Usage
14+
## 使用
1515

16-
[Documentation: Using loaders](http://webpack.github.io/docs/using-loaders.html)
16+
[文档:使用loaders](http://webpack.github.io/docs/using-loaders.html)
1717

1818
``` js
1919
var Component = require("react-proxy-loader!./Component");
20-
// => returns the proxied component (It loads on demand.)
21-
// (webpack creates an additional chunk for this component and its dependencies)
20+
// => 返回代理组件(它按需加载。)
21+
// (webpack为此组件及其依赖项创建一个附加块)
2222

2323
var ComponentProxyMixin = require("react-proxy-loader!./Component").Mixin;
24-
// => returns a mixin for the proxied component
25-
// (This allows you to setup rendering for the loading state for the proxy)
24+
// => 返回代理组件的mixin
25+
// (这允许您为prox的加载状态设置渲染)
2626
var ComponentProxy = React.createClass({
2727
mixins: [ComponentProxyMixin],
2828
renderUnavailable: function() {
@@ -31,11 +31,12 @@ var ComponentProxy = React.createClass({
3131
});
3232
```
3333

34-
The proxy is a react component. All properties are transferred to the wrapped component.
34+
代理是一个react组件。所有属性都将传输到包装组件。
3535

3636
### Configuration
37+
### 配置
3738

38-
Instead of (or in addition to) inlining the loader call you can also specify the proxied components in your configuration:
39+
代替(或除了)内联加载器调用之外,还可以在配置中指定代理组件:
3940

4041
``` js
4142
module.exports = {
@@ -55,9 +56,9 @@ module.exports = {
5556
};
5657
```
5758

58-
### Chunk name
59+
### 块名称
5960

60-
You can give the chunk a name with the `name` query parameter:
61+
您可以使用 `name` 查询参数为该块提供名称:
6162

6263
``` js
6364
var Component = require("react-proxy-loader?name=chunkName!./Component");
@@ -69,4 +70,4 @@ MIT (http://www.opensource.org/licenses/mit-license.php)
6970

7071
***
7172

72-
> 原文:https://webpack.js.org/loaders/react-proxy-loader/
73+
> 原文:https://webpack.js.org/loaders/react-proxy-loader/

0 commit comments

Comments
 (0)