Skip to content

Commit 16b5be5

Browse files
Merge pull request webpack#111 from dear-lizhihua/cn
/content/configuration/externals.md
2 parents 2ba3eaa + 645beb8 commit 16b5be5

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

components/navigation/navigation.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let Sections = [
1919
children: [
2020
{ title: 'API', url: 'api' },
2121
{ title: '配置', url: 'configuration' },
22-
{ title: '加载器', url: 'loaders' },
22+
{ title: 'LOADER', url: 'loaders' },
2323
{ title: '插件', url: 'plugins' },
2424
{ title: '开发', url: 'development' }
2525
]

content/configuration/externals.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ contributors:
77
- pksjce
88
---
99

10-
`externals` configuration in webpack provides a way of not including a dependency in the bundle. Instead the created bundle relies on that dependency to be present in the consumers environment.
11-
This typically applies to library developers though application developers can make good use of this feature too.
10+
webpack 中的 `externals` 配置提供了「不从 bundle 中引用依赖」的方式。解决的是,所创建的 bundle 依赖于那些存在于用户环境(consumer environment)中的依赖。
11+
此选项通常适用于 library 开发人员,但应用程序开发人员也可以充分利用此功能。
1212

1313
## `externals`
1414

1515
`string` `regex` `function` `array` `object`
1616

17-
**防止打包**某些 `import` 的包(package),而是*在运行时再去获取这些外部扩展包(package)*
17+
**防止**将某些 `import` (package)**打包**到 bundle 中,而是*在运行时(runtime)再去从外部获取这些扩展包(external package)*
1818

19-
例如,从 CDN 引入 [jQuery](https://jquery.com/)而不是把它打包在源文件中
19+
例如,从 CDN 引入 [jQuery](https://jquery.com/)而不是把它打包
2020

2121
**index.html**
2222

@@ -36,30 +36,30 @@ externals: {
3636
}
3737
```
3838

39-
这样就剥离了那些不需要改动的独立模块,换句话,下面展示的代码还可以正常运行:
39+
这样就剥离了那些不需要改动的依赖模块,换句话,下面展示的代码还可以正常运行:
4040

4141
```javascript
4242
import $ from 'jquery';
4343

4444
$('.my-element').animate(...);
4545
```
4646

47-
T> __consumer__ here is any end user application that includes the library that you have bundled using webpack.
47+
T> __用户(consumer)__,在这里是指任何用户应用程序终端(end user application),并且包含了使用 webpack 打包的 library
4848

49-
Your bundle which has external dependencies can be used in various module contexts mainly [CommonJS, AMD, global and ES2015 modules](/concepts/modules). The external library may be available in any of the above form but under different variables.
49+
有外部依赖(external dependency)的 bundle 能在多种模块上下文(module context)(大体上分为 [CommonJS, AMD, 全局变量和 ES2015 模块](/concepts/modules))中使用。外部 library 可以是上述任何的模块形式,但是必须在不同变量下。
5050

51-
`externals` supports the following module contexts
51+
`externals` 支持以下模块上下文(module context)
5252

53-
* __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.
54-
* __commonjs__ - The consumer application may be using a CommonJS module system and hence the external library should be available as a CommonJS module.
55-
* __commonjs2__ - Similar to the above line but where the export is `module.exports.default`.
56-
* __amd__ - Similar to the above line but using AMD module system.
53+
* __global__ - 外部 library 能够作为全局变量使用。用户可以通过在 script 标签中引入来实现。这是 externals 的默认设置。
54+
* __commonjs__ - 用户(consumer)应用程序可能使用 CommonJS 模块系统,因此外部 library 应该使用 CommonJS 模块系统,并且应该是一个 CommonJS 模块。
55+
* __commonjs2__ - 类似上面几行,但导出的是 `module.exports.default`
56+
* __amd__ - 类似上面几行,但使用 AMD 模块系统。
5757

58-
`externals` accepts various syntax and interprets them in different manners.
58+
`externals` 接受各种语法,并且按照不同方式去解释他们。
5959

6060
### string
6161

62-
`jQuery` in the externals indicates that your bundle will need `jQuery` variable in the global form.
62+
externals 中的 `jQuery`,表示你的 bundle 需要访问全局形式的 `jQuery` 变量。
6363

6464
### array
6565

@@ -69,7 +69,7 @@ externals: {
6969
}
7070
```
7171

72-
`subtract: ['./math', 'subtract']` converts to a parent child construct, where `./math` is the parent module and your bundle only requires the subset under `subtract` variable.
72+
`subtract: ['./math', 'subtract']` 转换为父子结构,其中 `./math` 是父模块,而 bundle 只引用 `subtract` 变量下的子集。
7373

7474
### object
7575

@@ -78,7 +78,7 @@ externals : {
7878
react: 'react'
7979
}
8080

81-
// or
81+
// 或者
8282

8383
externals : {
8484
lodash : {
@@ -89,7 +89,7 @@ externals : {
8989
}
9090
```
9191

92-
This syntax is used to describe all the possible ways that an external library can be available. `lodash` here is available as `lodash` under AMD and CommonJS module systems but available as `_` in a global variable form.
92+
此语法用于描述所有外部 library 可用的访问方式。这里 `lodash` 这个外部 library 可以在 AMD CommonJS 模块系统中通过 `lodash` 访问,但在全局变量形式下用 `_` 访问。
9393

9494
### function
9595

@@ -99,7 +99,7 @@ This syntax is used to describe all the possible ways that an external library c
9999

100100
?> TODO - I think its overkill to list externals as regex.
101101

102-
For more information on how to use this configuration, please refer to the article on [how to author a library](/guides/author-libraries).
102+
关于如何使用此 externals 配置的更多信息,请参考[如何编写 library](/guides/author-libraries)
103103

104104
***
105105

0 commit comments

Comments
 (0)