Skip to content

Commit 35d1511

Browse files
Merge pull request webpack#161 from dear-lizhihua/cn
/content/configuration/resolve.md
2 parents 5a7aaf8 + 609f5ff commit 35d1511

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

content/configuration/resolve.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@ contributors:
99
- sebastiandeutsch
1010
---
1111

12-
These options change how modules are resolved. webpack provides reasonable defaults, but it is possible to change the resolving in detail.
13-
Have a look at [Module Resolution](/concepts/module-resolution) for more explanation of how the resolver works.
12+
这些选项能设置模块如何被解析。webpack 提供合理的默认值,但是还是可能会修改一些解析的细节。
13+
关于 resolver 具体如何工作的更多解释说明,请查看[模块解析方式](/concepts/module-resolution)
1414

1515
## `resolve`
1616

1717
`object`
1818

19-
Configure how modules are resolved. For example, when calling `import "lodash"` in ES2015, the `resolve` options can change where webpack goes to look for `"lodash"` (see [`modules`](#resolve-modules)).
19+
配置模块如何解析。例如,当在 ES2015 中调用 `import "lodash"``resolve` 选项能够对 webpack 查找 `"lodash"` 的方式去做修改(查看[`模块`](#resolve-modules))。
2020

2121
## `resolve.alias`
2222

2323
`object`
2424

25-
Create aliases to `import` or `require` certain modules more easily. For example, to alias a bunch of commonly used `src/` folders:
25+
创建 `import` `require` 的别名,来确保模块引入变得更简单。例如,一些位于 `src/` 文件夹下的常用模块:
2626

2727
```js
2828
alias: {
@@ -31,36 +31,36 @@ alias: {
3131
}
3232
```
3333

34-
Now, instead of using relative paths when importing like so:
34+
现在,替换「在导入时使用相对路径」这种方式,就像这样:
3535

3636
```js
3737
import Utility from '../../utilities/utility';
3838
```
3939

40-
you can use the alias:
40+
你可以这样使用别名:
4141

4242
```js
4343
import Utility from 'Utilities/utility';
4444
```
4545

46-
A trailing `$` can also be added to the given object's keys to signify an exact match:
46+
也可以在给定对象的键后的末尾添加 `$`,以表示精准匹配:
4747

4848
```js
4949
alias: {
5050
xyz$: path.resolve(__dirname, 'path/to/file.js')
5151
}
5252
```
5353

54-
which would yield these results:
54+
这将产生以下结果:
5555

5656
```js
57-
import Test1 from 'xyz'; // Success, file.js is resolved and imported
58-
import Test2 from 'xyz/file.js'; // Error, /path/to/file.js/file.js is invalid
57+
import Test1 from 'xyz'; // 成功,file.js 被解析和导入。
58+
import Test2 from 'xyz/file.js'; // 错误,/path/to/file.js/file.js 是无效的
5959
```
6060

61-
The following table explains a lot more cases:
61+
下面的表格展示了许多情况:
6262

63-
| `alias:` | `import "xyz"` | `import "xyz/file.js"` |
63+
| `别名:` | `import "xyz"` | `import "xyz/file.js"` |
6464
| -------- | ---------------- | -------------------------|
6565
| `{}` | `/abc/node_modules/xyz/index.js` | `/abc/node_modules/xyz/file.js` |
6666
| `{ xyz: "/abs/path/to/file.js" }` | `/abs/path/to/file.js` | error |
@@ -77,16 +77,16 @@ The following table explains a lot more cases:
7777
| `{ xyz: "xyz/dir" }` | `/abc/node_modules/xyz/dir/index.js` | `/abc/node_modules/xyz/dir/file.js` |
7878
| `{ xyz$: "xyz/dir" }` | `/abc/node_modules/xyz/dir/index.js` | `/abc/node_modules/xyz/file.js` |
7979

80-
`index.js` may resolve to another file if defined in the `package.json`.
80+
如果在 `package.json` 中定义,`index.js` 可能会被解析为另一个文件。
8181

82-
`/abc/node_modules` may resolve in `/node_modules` too.
82+
`/abc/node_modules` 也可能在 `/node_modules` 中解析。
8383

8484

8585
## `resolve.aliasFields`
8686

8787
`string`
8888

89-
Specify a field, such as `browser`, to be parsed according to [this specification](https://github.com/defunctzombie/package-browser-field-spec). Default:
89+
指定一个字段,例如 `browser`,根据[此规范](https://github.com/defunctzombie/package-browser-field-spec)进行解析。默认:
9090

9191
```js
9292
aliasFields: ["browser"]
@@ -97,7 +97,7 @@ aliasFields: ["browser"]
9797

9898
`array`
9999

100-
The JSON files to use for descriptions. Default:
100+
用于描述的 JSON 文件。默认:
101101

102102
```js
103103
descriptionFiles: ["package.json"]
@@ -108,7 +108,7 @@ descriptionFiles: ["package.json"]
108108

109109
`boolean`
110110

111-
If `true`, it will not allow extension-less files. So by default `require('./foo')` works if `./foo` has a `.js` extension, but with this enabled only `require('./foo.js')` will work. Default:
111+
如果是 `true`,将不允许无扩展名(extension-less)文件。默认如果 `./foo``.js` 扩展,`require('./foo')` 可以正常运行。但如果启用此选项,只有 `require('./foo.js')` 能够正常工作。默认:
112112

113113
```js
114114
enforceExtension: false
@@ -119,7 +119,7 @@ enforceExtension: false
119119

120120
`boolean`
121121

122-
Whether to require to use an extension for modules (e.g. loaders). Default:
122+
对模块是否需要使用的扩展(例如 loader)。默认:
123123

124124
```js
125125
enforceModuleExtension: false
@@ -130,19 +130,19 @@ enforceModuleExtension: false
130130

131131
`array`
132132

133-
Automatically resolve certain extensions. This defaults to:
133+
自动解析确定的扩展。默认值为:
134134

135135
```js
136136
extensions: [".js", ".json"]
137137
```
138138

139-
which is what enables users to leave off the extension when importing:
139+
能够使用户在引入模块时不带扩展:
140140

141141
```js
142142
import File from '../path/to/file'
143143
```
144144

145-
W> Using this will **override the default array**, meaning that webpack will no longer try to resolve modules using the default extensions. For modules that are imported with their extension, e.g. `import SomeFile from "./somefile.ext"`, to be properly resolved, a string containing "\*" must be included in the array.
145+
W> 使用此选项,会**覆盖默认数组**,这就意味着 webpack 将不再尝试使用默认扩展来解析模块。对于使用其扩展导入的模块,例如,`import SomeFile from "./somefile.ext"`,要想正确的解析,一个包含“\*”的字符串必须包含在数组中。
146146

147147

148148
## `resolve.mainFields`

0 commit comments

Comments
 (0)