@@ -4,17 +4,18 @@ source: https://raw.githubusercontent.com/webpack-contrib/bundle-loader/master/R
4
4
edit : https://github.com/webpack-contrib/bundle-loader/edit/master/README.md
5
5
repo : https://github.com/webpack-contrib/bundle-loader
6
6
---
7
- Bundle loader for webpack
7
+ 应用于 webpack 的 bundle loader
8
8
9
- ## Install
9
+ ## 安装
10
10
11
11
``` bash
12
12
npm i bundle-loader --save
13
13
```
14
14
15
- ## Usage
15
+ ## 用法
16
16
17
17
** webpack.config.js**
18
+
18
19
``` js
19
20
module .exports = {
20
21
module: {
@@ -28,46 +29,47 @@ module.exports = {
28
29
}
29
30
```
30
31
31
- The chunk is requested, when you require the bundle.
32
+ 当你引用 bundle-loader 时, chunk 会被请求。
32
33
33
34
** file.js**
34
35
``` js
35
36
import bundle from ' ./file.bundle.js' ;
36
37
```
37
38
38
- To wait until the chunk is available (and get the exports)
39
- you need to async wait for it.
39
+ 需要使用异步处理,
40
+ 以使得 chunk 在浏览器加载(以及在获取其导出)时可用。
40
41
41
42
``` js
42
43
bundle ((file ) => {
43
- // use the file like it was required
44
+ // 按需引入文件
44
45
const file = require (' ./file.js' )
45
46
});
46
47
```
47
48
48
- This wraps the ` require('file.js') ` in a ` require.ensure ` block
49
+ 上述代码会将 ` require('file.js') ` 包裹在一段 ` require.ensure ` 代码块中。
49
50
50
- Multiple callbacks can be added. They will be executed in the order of addition.
51
+ 可以添加多个回调函数,这些回调函数会按照添加的顺序依次执行。
51
52
52
53
``` js
53
54
bundle (callbackTwo)
54
55
bundle (callbackThree)
55
56
```
56
57
57
- If a callback is added after dependencies were loaded, it will be called immediately.
58
+ 当依赖模块都加载完毕时, 如果此时添加一个回调函数,回到函数将会立即执行。
58
59
59
- ## Options
60
+ ## 选项
60
61
61
- | Name | Type | Default | Description |
62
+ | 选项名 | 类型 | 默认值 | 描述 |
62
63
| :--:| :--:| :-----:| :----------|
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 配置自定义文件名 |
65
66
66
67
### ` lazy `
67
68
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),请使用:
69
70
70
71
** webpack.config.js**
72
+
71
73
``` js
72
74
{
73
75
loader: ' bundle-loader' ,
@@ -83,14 +85,15 @@ import bundle from './file.bundle.js'
83
85
bundle ((file ) => {... })
84
86
```
85
87
86
- > ℹ️ The chunk is not requested until you call the load function
88
+ > ℹ️ 只有调用 load 函数时, chunk 才会被请求(request)
87
89
88
90
### ` name `
89
91
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 ) 。
92
94
93
95
** webpack.config.js**
96
+
94
97
``` js
95
98
{
96
99
loader: ' bundle-loader' ,
@@ -100,26 +103,26 @@ See [documentation](https://github.com/webpack/loader-utils#interpolatename).
100
103
}
101
104
```
102
105
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 名称。
105
108
106
- ## Examples
109
+ ## 示例
107
110
108
111
``` js
109
112
import bundle from ' ./file.bundle.js'
110
113
```
111
114
112
115
** webpack.config.js**
113
- ``` js
116
+ ``` js
114
117
module .exports = {
115
118
entry: {
116
- index: ' ./App.js'
119
+ index: ' ./App.js'
117
120
},
118
121
output: {
119
122
path: path .resolve (__dirname , ' dest' ),
120
123
filename: ' [name].js' ,
121
- // or whatever other format you want
122
- chunkFilename: ' [name].[id].js' ,
124
+ // 此处可以自定义其他格式
125
+ chunkFilename: ' [name].[id].js'
123
126
},
124
127
module: {
125
128
rules: [
@@ -137,13 +140,13 @@ module.exports = {
137
140
}
138
141
```
139
142
140
- Normal chunks will show up using the ` filename ` rule above, and be named according to their ` [chunkname] ` .
143
+ 一般情况下,chunk 会使用上面的 ` filename ` 规则,并根据其对应的 ` [chunkname] ` 命名。
141
144
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 ` 。
143
146
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] ` 不会生效。
145
148
146
- ## Maintainers
149
+ ## 维护人员
147
150
148
151
<table >
149
152
<tbody >
0 commit comments