@@ -19,22 +19,22 @@ related:
19
19
url : https://en.wikipedia.org/wiki/Asynchronous_module_definition
20
20
---
21
21
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 ` 和其他变量,来访问编译过程中的某些数据。
23
23
24
24
25
25
### ` module.loaded ` (NodeJS)
26
26
27
- This is ` false ` if the module is currently executing, and ` true ` if the sync execution has finished.
27
+ ` false ` 表示该模块正在执行, ` true ` 表示同步执行已经完成。
28
28
29
29
30
30
### ` module.hot ` (webpack-specific)
31
31
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 ) 。
33
33
34
34
35
35
### ` module.id ` (CommonJS)
36
36
37
- The ID of the current module.
37
+ 当前模块的 ID。
38
38
39
39
``` javascript
40
40
module .id === require .resolve (' ./file.js' );
@@ -43,20 +43,20 @@ module.id === require.resolve('./file.js');
43
43
44
44
### ` module.exports ` (CommonJS)
45
45
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 ` 对模块进行调用时返回的值(默认为一个新对象)。
47
47
48
48
``` javascript
49
49
module .exports = function doSomething () {
50
50
// Do something...
51
51
};
52
52
```
53
53
54
- W> This CANNOT be used in an asynchronous function.
54
+ W> 无法在异步函数中访问该变量。
55
55
56
56
57
57
### ` exports ` (CommonJS)
58
58
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 ` 不再会被导出。
60
60
61
61
``` javascript
62
62
exports .someValue = 42 ;
@@ -71,39 +71,39 @@ exports.aFunction = function doSomething() {
71
71
72
72
### ` global ` (NodeJS)
73
73
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 ) .
75
75
76
76
77
77
### ` process ` (NodeJS)
78
78
79
- See [ node.js process] ( https://nodejs.org/api/process.html ) .
79
+ 见 [ node.js process] ( https://nodejs.org/api/process.html ) .
80
80
81
81
82
82
### ` __dirname ` (NodeJS)
83
83
84
- Depending on the configuration option ` node.__dirname ` :
84
+ 取决于 ` node.__dirname ` 配置选项:
85
85
86
86
- ` false ` : Not defined
87
87
- ` mock ` : equal to ` '/' `
88
88
- ` true ` : [ node.js __ dirname] ( https://nodejs.org/api/globals.html#globals_dirname )
89
89
90
- If used inside an expression that is parsed by the Parser, the configuration option is treated as ` true ` .
90
+ 如果在一个被 Parser 解析的表达式内部使用,则配置选项会被当作 ` true ` 处理。
91
91
92
92
93
93
### ` __filename ` (NodeJS)
94
94
95
- Depending on the configuration option ` node.__filename ` :
95
+ 取决于 ` node.__filename ` 配置选项:
96
96
97
97
- ` false ` : Not defined
98
98
- ` mock ` : equal to ` '/index.js' `
99
99
- ` true ` : [ node.js __ filename] ( https://nodejs.org/api/globals.html#globals_filename )
100
100
101
- If used inside an expression that is parsed by the Parser, the configuration option is treated as ` true ` .
101
+ 如果在一个被 Parser 解析的表达式内部使用,则配置选项会被当作 ` true ` 处理。
102
102
103
103
104
- ### ` __resourceQuery ` (webpack-specific )
104
+ ### ` __resourceQuery ` (webpack 特有变量 )
105
105
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 ` 中可访问。
107
107
108
108
``` javascript
109
109
require (' file.js?test' );
@@ -116,63 +116,63 @@ __resourceQuery === '?test';
116
116
```
117
117
118
118
119
- ### ` __webpack_public_path__ ` (webpack-specific )
119
+ ### ` __webpack_public_path__ ` (webpack 特有变量 )
120
120
121
- Equals the configuration option's ` output.publicPath ` .
121
+ 等同于 ` output.publicPath ` 配置选项。
122
122
123
123
124
- ### ` __webpack_require__ ` (webpack-specific )
124
+ ### ` __webpack_require__ ` (webpack 特有变量 )
125
125
126
- The raw require function. This expression isn't parsed by the Parser for dependencies.
126
+ 原始 require 函数。这个表达式不会被解析器解析为依赖。
127
127
128
128
129
- ### ` __webpack_chunk_load__ ` (webpack-specific )
129
+ ### ` __webpack_chunk_load__ ` (webpack 特有变量 )
130
130
131
- The internal chunk loading function. Takes two arguments:
131
+ 内部 chunk 载入函数,有两个输入参数:
132
132
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 载入后调用的回调函数。
135
135
136
136
137
- ### ` __webpack_modules__ ` (webpack-specific )
137
+ ### ` __webpack_modules__ ` (webpack 特有变量 )
138
138
139
- Access to the internal object of all modules.
139
+ 访问所有模块的内部对象。
140
140
141
141
142
- ### ` __webpack_hash__ ` (webpack-specific )
142
+ ### ` __webpack_hash__ ` (webpack 特有变量 )
143
143
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 信息的获取。
145
145
146
146
147
- ### ` __non_webpack_require__ ` (webpack-specific )
147
+ ### ` __non_webpack_require__ ` (webpack 特有变量 )
148
148
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 函数,可以完成一些酷炫操作。
150
150
151
151
152
- ### ` __webpack_exports_info__ ` (webpack-specific )
152
+ ### ` __webpack_exports_info__ ` (webpack 特有变量 )
153
153
154
- In modules , ` __webpack_exports_info__ ` is available to allow exports introspection:
154
+ 在模块中 , ` __webpack_exports_info__ ` 可以被获取到,以便导出模块用以自我检查:
155
155
156
- - ` __webpack_exports_info__ ` is always ` true `
156
+ - ` __webpack_exports_info__ ` 总是 ` true `
157
157
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 `
159
159
160
- - ` __webpack_exports_info__.<exportName>.useInfo ` is
160
+ - ` __webpack_exports_info__.<exportName>.useInfo ` 是
161
161
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 ` 当没有可用信息时
166
166
167
- - ` __webpack_exports_info__.<exportName>.provideInfo ` is
167
+ - ` __webpack_exports_info__.<exportName>.provideInfo ` 是
168
168
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 ` 当没有可用信息时
173
173
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 `
175
175
176
- ### ` DEBUG ` (webpack-specific )
176
+ ### ` DEBUG ` (webpack 特有变量 )
177
177
178
- Equals the configuration option ` debug ` .
178
+ 等同于 ` debug ` 配置选项。
0 commit comments