Skip to content

Commit a0aa7ae

Browse files
author
袁程
committed
docs(cn): translate src/content/api/module-variables.md
1 parent 8ff0e62 commit a0aa7ae

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/content/api/module-variables.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ related:
1919
url: https://en.wikipedia.org/wiki/Asynchronous_module_definition
2020
---
2121

22-
This section covers all __variables__ available in code compiled with webpack. Modules will have access to certain data from the compilation process through `module` and other variables.
22+
本章节涵盖了使用 webpack 编译的代码中所有的 __变量__。模块将通过 `module` 和其他变量,来访问编译过程中的某些数据。
2323

2424

2525
### `module.loaded` (NodeJS)
2626

27-
This is `false` if the module is currently executing, and `true` if the sync execution has finished.
27+
`false` 表示该模块正在执行, `true` 表示同步执行已经完成。
2828

2929

3030
### `module.hot` (webpack-specific)
3131

32-
Indicates whether or not [Hot Module Replacement](/concepts/hot-module-replacement) is enabled and provides an interface to the process. See the [HMR API page](/api/hot-module-replacement) for details.
32+
表示 [模块热替换(Hot Module Replacement)](/concepts/hot-module-replacement) 是否启用,并给进程提供一个接口。详细说明请查看 [模块热替换 API 页面](/api/hot-module-replacement)
3333

3434

3535
### `module.id` (CommonJS)
3636

37-
The ID of the current module.
37+
当前模块的 ID
3838

3939
``` javascript
4040
module.id === require.resolve('./file.js');
@@ -43,20 +43,20 @@ module.id === require.resolve('./file.js');
4343

4444
### `module.exports` (CommonJS)
4545

46-
Defines the value that will be returned when a consumer makes a `require` call to the module (defaults to a new object).
46+
调用者通过 `require` 对模块进行调用时返回的值(默认为一个新对象)。
4747

4848
``` javascript
4949
module.exports = function doSomething() {
5050
// Do something...
5151
};
5252
```
5353

54-
W> This CANNOT be used in an asynchronous function.
54+
W> 无法在异步函数中访问该变量。
5555

5656

5757
### `exports` (CommonJS)
5858

59-
This variable is equal to the default value of `module.exports` (i.e. an object). If `module.exports` gets overwritten, `exports` will no longer be exported.
59+
该变量默认值为 `module.exports`(即一个对象)。 如果 `module.exports` 被重写的话, `exports` 不再会被导出。
6060

6161
``` javascript
6262
exports.someValue = 42;
@@ -71,39 +71,39 @@ exports.aFunction = function doSomething() {
7171

7272
### `global` (NodeJS)
7373

74-
See [node.js global](https://nodejs.org/api/globals.html#globals_global).
74+
[node.js global](https://nodejs.org/api/globals.html#globals_global).
7575

7676

7777
### `process` (NodeJS)
7878

79-
See [node.js process](https://nodejs.org/api/process.html).
79+
[node.js process](https://nodejs.org/api/process.html).
8080

8181

8282
### `__dirname` (NodeJS)
8383

84-
Depending on the configuration option `node.__dirname`:
84+
取决于 `node.__dirname` 配置选项:
8585

8686
- `false`: Not defined
8787
- `mock`: equal to `'/'`
8888
- `true`: [node.js __dirname](https://nodejs.org/api/globals.html#globals_dirname)
8989

90-
If used inside an expression that is parsed by the Parser, the configuration option is treated as `true`.
90+
如果在一个被 Parser 解析的表达式内部使用,则配置选项会被当作 `true` 处理。
9191

9292

9393
### `__filename` (NodeJS)
9494

95-
Depending on the configuration option `node.__filename`:
95+
取决于 `node.__filename` 配置选项:
9696

9797
- `false`: Not defined
9898
- `mock`: equal to `'/index.js'`
9999
- `true`: [node.js __filename](https://nodejs.org/api/globals.html#globals_filename)
100100

101-
If used inside an expression that is parsed by the Parser, the configuration option is treated as `true`.
101+
如果在一个被 Parser 解析的表达式内部使用,则配置选项会被当作 `true` 处理。
102102

103103

104-
### `__resourceQuery` (webpack-specific)
104+
### `__resourceQuery` (webpack 特有变量)
105105

106-
The resource query of the current module. If the following `require` call was made, then the query string would be available in `file.js`.
106+
当前模块的资源查询(resource query) 。如果进行了如下的 `reqiure` 调用,那么查询字符串(query string)在`file.js` 中可访问。
107107

108108
``` javascript
109109
require('file.js?test');
@@ -116,63 +116,63 @@ __resourceQuery === '?test';
116116
```
117117

118118

119-
### `__webpack_public_path__` (webpack-specific)
119+
### `__webpack_public_path__` (webpack 特有变量)
120120

121-
Equals the configuration option's `output.publicPath`.
121+
等同于 `output.publicPath` 配置选项。
122122

123123

124-
### `__webpack_require__` (webpack-specific)
124+
### `__webpack_require__` (webpack 特有变量)
125125

126-
The raw require function. This expression isn't parsed by the Parser for dependencies.
126+
原始 require 函数。这个表达式不会被解析器解析为依赖。
127127

128128

129-
### `__webpack_chunk_load__` (webpack-specific)
129+
### `__webpack_chunk_load__` (webpack 特有变量)
130130

131-
The internal chunk loading function. Takes two arguments:
131+
内部 chunk 载入函数,有两个输入参数:
132132

133-
- `chunkId` The id for the chunk to load.
134-
- `callback(require)` A callback function called once the chunk is loaded.
133+
- `chunkId` 需要载入的 chunk id。
134+
- `callback(require)` chunk 载入后调用的回调函数。
135135

136136

137-
### `__webpack_modules__` (webpack-specific)
137+
### `__webpack_modules__` (webpack 特有变量)
138138

139-
Access to the internal object of all modules.
139+
访问所有模块的内部对象。
140140

141141

142-
### `__webpack_hash__` (webpack-specific)
142+
### `__webpack_hash__` (webpack 特有变量)
143143

144-
This variable is only available with the `HotModuleReplacementPlugin` or the `ExtendedAPIPlugin`. It provides access to the hash of the compilation.
144+
这个变量只有在启用 `HotModuleReplacementPlugin` 或者 `ExtendedAPIPlugin` 时才生效。这个变量提供对编译过程中(compilation)的 hash 信息的获取。
145145

146146

147-
### `__non_webpack_require__` (webpack-specific)
147+
### `__non_webpack_require__` (webpack 特有变量)
148148

149-
Generates a `require` function that is not parsed by webpack. Can be used to do cool stuff with a global require function if available.
149+
生成一个不会被 webpack 解析的 `require` 函数。配合全局可以获取到的 require 函数,可以完成一些酷炫操作。
150150

151151

152-
### `__webpack_exports_info__` (webpack-specific)
152+
### `__webpack_exports_info__` (webpack 特有变量)
153153

154-
In modules, `__webpack_exports_info__` is available to allow exports introspection:
154+
在模块中, `__webpack_exports_info__` 可以被获取到,以便导出模块用以自我检查:
155155

156-
- `__webpack_exports_info__` is always `true`
156+
- `__webpack_exports_info__` 总是 `true`
157157

158-
- `__webpack_exports_info__.<exportName>.used` is `false` when the export is known to be unused, `true` otherwise
158+
- 当导出模块未被使用时 `__webpack_exports_info__.<exportName>.used` `false`, 否则是 `true`
159159

160-
- `__webpack_exports_info__.<exportName>.useInfo` is
160+
- `__webpack_exports_info__.<exportName>.useInfo`
161161

162-
- `false` when the export is known to be unused
163-
- `true` when the export is known to be used
164-
- `null` when the export usage could depend on runtime conditions
165-
- `undefined` when no info is available
162+
- `false` 当导出模块未被使用
163+
- `true` 当导出模块被使用
164+
- `null` 当导出模块的使用情况取决于运行时的条件
165+
- `undefined` 当没有可用信息时
166166

167-
- `__webpack_exports_info__.<exportName>.provideInfo` is
167+
- `__webpack_exports_info__.<exportName>.provideInfo`
168168

169-
- `false` when the export is known to be not provided
170-
- `true` when the export is known to be provided
171-
- `null` when the export provision could depend on runtime conditions
172-
- `undefined` when no info is available
169+
- `false` 当导出模块没有被提供
170+
- `true` 当导出模块被提供
171+
- `null` 当导出模块的提供情况取决于运行时的条件
172+
- `undefined` 当没有可用信息时
173173

174-
- Accessing the info from nested exports is possible: i. e. `__webpack_exports_info__.<exportName>.<exportName>.<exportName>.used`
174+
- 可以从嵌套的 exports 中得到相关信息: 例如 `__webpack_exports_info__.<exportName>.<exportName>.<exportName>.used`
175175

176-
### `DEBUG` (webpack-specific)
176+
### `DEBUG` (webpack 特有变量)
177177

178-
Equals the configuration option `debug`.
178+
等同于 `debug` 配置选项。

0 commit comments

Comments
 (0)