Skip to content

docs(cn): translate src/content/configuration/entry-context.md #757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions src/content/configuration/entry-context.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Entry and Context
title: 入口和上下文(entry and context)
sort: 4
contributors:
- sokra
Expand All @@ -11,14 +11,14 @@ contributors:
- smelukov
---

The entry object is where webpack looks to start building the bundle. The context is an absolute string to the directory that contains the entry files.
入口对象是用于 webpack 查找开始构建 bundle 的地方。上下文是入口文件所处的目录的绝对路径的字符串。


## `context`

`string`

The base directory, an __absolute path__, for resolving entry points and loaders from configuration.
基础目录,__绝对路径__,用于从配置中解析入口点(entry point)和 加载器(loader)。

``` js
const path = require('path');
Expand All @@ -29,7 +29,7 @@ module.exports = {
};
```

By default the current directory is used, but it's recommended to pass a value in your configuration. This makes your configuration independent from CWD (current working directory).
默认使用当前目录,但是推荐在配置中传入一个值。这使得你的配置独立于 CWD(current working directory, 当前工作目录)。

---

Expand All @@ -38,11 +38,11 @@ By default the current directory is used, but it's recommended to pass a value i

`string` `[string]` `object = { <key> string | [string] | object = { import string | [string], dependOn string | [string], filename string }}` `(function() => string | [string] | object = { <key> string | [string] } | object = { import string | [string], dependOn string | [string], filename string })`

The point or points where to start the application bundling process. If an array is passed then all items will be processed.
开始应用程序打包过程的一个或多个起点。如果传入数组,则会处理所有条目。

A dynamically loaded module is __not__ an entry point.
动态加载的模块 __不是__ 入口起点。

Simple rule: one entry point per HTML page. SPA: one entry point, MPA: multiple entry points.
简单规则:每个 HTML 页面都有一个入口起点。单页应用(SPA):一个入口起点,多页应用(MPA):多个入口起点。

```js
module.exports = {
Expand All @@ -58,11 +58,11 @@ module.exports = {

### Naming

If a string or array of strings is passed, the chunk is named `main`. If an object is passed, each key is the name of a chunk, and the value describes the entry point for the chunk.
如果传入一个字符串或字符串数组,chunk 会被命名为 `main`。如果传入一个对象,则每个属性的键(key)会是 chunk 的名称,该属性的值描述了 chunk 的入口点。

### Entry descriptor

If an object is passed the value might be a string, array of strings or a descriptor:
如果传入一个对象,对象的属性的值可以是一个字符串、字符串数组或者一个描述符(descriptor):

```js
module.exports = {
Expand All @@ -84,12 +84,12 @@ module.exports = {
};
```

Descriptor syntax might be used to pass additional options to an entry point.
描述符语法可以用来传入额外的选项给入口。


### Output filename

By default, the output filename for the entry chunk is extracted from [`output.filename`](/configuration/output/#outputfilename) but you can specify a custom output filename for a specific entry:
默认情况下,入口 chunk 的输出文件名是从 [`output.filename`](/configuration/output/#outputfilename) 中提取出来的,但你可以为特定的入口指定一个自定义的输出文件名。

```js
module.exports = {
Expand All @@ -102,12 +102,12 @@ module.exports = {
};
```

Descriptor syntax was used here to pass `filename`-option to the specific entry points.
描述符语法在这里被用来将 `filename`—选项传递给指定的入口点。


### Dependencies

By default, every entry chunk stores all the modules that it uses. With `dependOn`-option you can share the modules from one entry chunk to another:
默认情况下,每个入口 chunk 保存了全部其用的模块(modules)。使用 `dependOn`—选项你可以与另一个入口 chunk 共享模块:

```js
module.exports = {
Expand All @@ -119,9 +119,9 @@ module.exports = {
};
```

The `app` chunk will not contain the modules that `react-vendors` has.
`app` 这个 chunk 就不会包含 `react-vendors` 拥有的模块了.

Also you can specify multiple files per entry using array:
你也可以使用数组为一个入口指定多个文件:

```js
module.exports = {
Expand All @@ -135,9 +135,9 @@ module.exports = {

### Dynamic entry

If a function is passed then it will be invoked on every [make](/api/compiler-hooks/#make) event.
如果传入一个函数,那么它将会在每次 [make](/api/compiler-hooks/#make) 事件中被调用。

> Note that the make event triggers when webpack starts and for every invalidation when [watching for file changes](/configuration/watch/).
> 要注意的是,make 事件在 webpack 启动和每当 [监听文件变化](/configuration/watch/) 时都会触发。

```js
module.exports = {
Expand All @@ -146,7 +146,7 @@ module.exports = {
};
```

or
或者

```js
module.exports = {
Expand All @@ -155,16 +155,16 @@ module.exports = {
};
```

For example: you can use dynamic entries to get the actual entries from an external source (remote server, file system content or database):
例如,你可以使用动态入口来从外部来源(远程服务器,文件系统内容或者数据库)获取真正的入口:

__webpack.config.js__

``` js
module.exports = {
entry() {
return fetchPathsFromSomeExternalSource(); // returns a promise that will be resolved with something like ['src/main-layout.js', 'src/admin-layout.js']
return fetchPathsFromSomeExternalSource(); // 返回一个会被用像 ['src/main-layout.js', 'src/admin-layout.js'] 的东西 resolve 的 promise
}
};
```

When combining with the [`output.library`](/configuration/output/#outputlibrary) option: If an array is passed only the last item is exported.
当和 [`output.library`](/configuration/output/#outputlibrary) 选项结合:如果传入的是一个数组,只有数组的最后一个条目会被导出。