Skip to content

Commit a210777

Browse files
mercurywangWangZiyuQC-L
authored
docs(cn): translation src/content/loaders/bundle-loader.md (#783)
Co-authored-by: WangZiyu <[email protected]> Co-authored-by: QiChang Li <[email protected]>
1 parent 0ccf6e3 commit a210777

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

src/content/loaders/bundle-loader.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ source: https://raw.githubusercontent.com/webpack-contrib/bundle-loader/master/R
44
edit: https://github.com/webpack-contrib/bundle-loader/edit/master/README.md
55
repo: https://github.com/webpack-contrib/bundle-loader
66
---
7-
Bundle loader for webpack
7+
应用于 webpack 的 bundle loader
88

9-
## Install
9+
## 安装
1010

1111
```bash
1212
npm i bundle-loader --save
1313
```
1414

15-
## Usage
15+
## 用法
1616

1717
**webpack.config.js**
18+
1819
```js
1920
module.exports = {
2021
module: {
@@ -28,46 +29,47 @@ module.exports = {
2829
}
2930
```
3031

31-
The chunk is requested, when you require the bundle.
32+
当你引用 bundle-loader 时,chunk 会被请求。
3233

3334
**file.js**
3435
```js
3536
import bundle from './file.bundle.js';
3637
```
3738

38-
To wait until the chunk is available (and get the exports)
39-
you need to async wait for it.
39+
需要使用异步处理,
40+
以使得 chunk 在浏览器加载(以及在获取其导出)时可用。
4041

4142
```js
4243
bundle((file) => {
43-
// use the file like it was required
44+
// 按需引入文件
4445
const file = require('./file.js')
4546
});
4647
```
4748

48-
This wraps the `require('file.js')` in a `require.ensure` block
49+
上述代码会将 `require('file.js')` 包裹在一段 `require.ensure` 代码块中。
4950

50-
Multiple callbacks can be added. They will be executed in the order of addition.
51+
可以添加多个回调函数,这些回调函数会按照添加的顺序依次执行。
5152

5253
```js
5354
bundle(callbackTwo)
5455
bundle(callbackThree)
5556
```
5657

57-
If a callback is added after dependencies were loaded, it will be called immediately.
58+
当依赖模块都加载完毕时, 如果此时添加一个回调函数,回到函数将会立即执行。
5859

59-
## Options
60+
## 选项
6061

61-
|Name|Type|Default|Description|
62+
|选项名|类型|默认值|描述|
6263
|:--:|:--:|:-----:|:----------|
63-
|**`lazy`**|`{Boolean}`|`false`|Loads the imported bundle asynchronously|
64-
|**`name`**|`{String}`|`[id].[name]`|Configure a custom filename for your imported bundle|
64+
|**`lazy`**|`{Boolean}`|`false`| 异步加载导入的 bundle |
65+
|**`name`**|`{String}`|`[id].[name]`| 为导入的 bundle 配置自定义文件名 |
6566

6667
### `lazy`
6768

68-
The file is requested when you require the `bundle-loader`. If you want it to request it lazy, use:
69+
当使用 `bundle-loader` 时,文件会被请求(request)。如果想让文件按需加载(request it lazy),请使用:
6970

7071
**webpack.config.js**
72+
7173
```js
7274
{
7375
loader: 'bundle-loader',
@@ -83,14 +85,15 @@ import bundle from './file.bundle.js'
8385
bundle((file) => {...})
8486
```
8587

86-
> ℹ️ The chunk is not requested until you call the load function
88+
> ℹ️ 只有调用 load 函数时,chunk 才会被请求(request)
8789
8890
### `name`
8991

90-
You may set name for a bundle using the `name` options parameter.
91-
See [documentation](https://github.com/webpack/loader-utils#interpolatename).
92+
可以通过配置中 `name` 选项参数,来设置 bundle 的名称。
93+
请查阅相关[文档](https://github.com/webpack/loader-utils#interpolatename)
9294

9395
**webpack.config.js**
96+
9497
```js
9598
{
9699
loader: 'bundle-loader',
@@ -100,26 +103,26 @@ See [documentation](https://github.com/webpack/loader-utils#interpolatename).
100103
}
101104
```
102105

103-
> :warning: chunks created by the loader will be named according to the
104-
[`output.chunkFilename`](/configuration/output/#outputchunkfilename) rule, which defaults to `[id].[name]`. Here `[name]` corresponds to the chunk name set in the `name` options parameter.
106+
> :warning: 一旦 loader 创建了 chunk,将遵循以下命名规则 [`output.chunkFilename`](/configuration/output/#outputchunkfilename) 规则,
107+
默认是 `[id].[name]`。这里 `[name]` 对应着配置中 name 选项参数设置的 chunk 名称。
105108

106-
## Examples
109+
## 示例
107110

108111
```js
109112
import bundle from './file.bundle.js'
110113
```
111114

112115
**webpack.config.js**
113-
``` js
116+
```js
114117
module.exports = {
115118
entry: {
116-
index: './App.js'
119+
index: './App.js'
117120
},
118121
output: {
119122
path: path.resolve(__dirname, 'dest'),
120123
filename: '[name].js',
121-
// or whatever other format you want
122-
chunkFilename: '[name].[id].js',
124+
// 此处可以自定义其他格式
125+
chunkFilename: '[name].[id].js'
123126
},
124127
module: {
125128
rules: [
@@ -137,13 +140,13 @@ module.exports = {
137140
}
138141
```
139142

140-
Normal chunks will show up using the `filename` rule above, and be named according to their `[chunkname]`.
143+
一般情况下,chunk 会使用上面的 `filename` 规则,并根据其对应的 `[chunkname]` 命名。
141144

142-
Chunks from `bundle-loader`, however will load using the `chunkFilename` rule, so the example files will produce `my-chunk.1.js` and `file-2.js` respectively.
145+
然而,来自 `bundle-loader` 中的 chunk 会使用 `chunkFilename` 规则命名。因此,打包后的示例文件最终将生成为 `my-chunk.1.js` `file-2.js`
143146

144-
You can also use `chunkFilename` to add hash values to the filename, since putting `[hash]` in the bundle options parameter does not work correctly.
147+
当然,你也可以在 `chunkFilename` 添加哈希值作为文件名的一部分,这是因为在 bundle 的配置选项中放置 `[hash]` 不会生效。
145148

146-
## Maintainers
149+
## 维护人员
147150

148151
<table>
149152
<tbody>

0 commit comments

Comments
 (0)