1
1
---
2
- title : Resolvers
2
+ title : 解析器( Resolvers)
3
3
group : Plugins
4
4
sort : 13
5
5
contributors :
6
6
- EugeneHlushko
7
7
---
8
8
9
- Resolvers are created using the ` enhanced-resolve ` package. The ` Resolver `
10
- class extends the ` tapable ` class and uses ` tapable ` to provide a few hooks.
11
- The ` enhanced-resolve ` package can be used directly to create new resolvers,
12
- however any [ ` compiler ` instance ] ( /api/node/#compiler-instance ) has a few resolver instances that can be
13
- tapped into.
9
+ 解析器是使用 ` enhanced-resolve ` 库创建的。 ` Resolver ` 类
10
+ 拓展了 ` tapable ` 类,并使用 ` tapable ` 来提供了一些钩子。
11
+ ` enhanced-resolve ` 可以直接用于创建新的解析器,
12
+ 但是,任何 [ ` compiler ` 实例 ] ( /api/node/#compiler-instance ) 都有一些解析器实例,可以
13
+ 被 ` tap ` 进去。
14
14
15
- Before reading on, make sure to have a look at the
16
- [ ` enhanced-resolve ` ] ( https://github.com/webpack/enhanced-resolve ) and [ ` tapable ` ] ( /api/plugins/#tapable ) documentation.
15
+ 在继续阅读之前,请确保你已经读过
16
+ [ ` enhanced-resolve ` ] ( https://github.com/webpack/enhanced-resolve ) 和 [ ` tapable ` ] ( /api/plugins/#tapable ) 文档。
17
17
18
18
19
- ## Types
19
+ ## 类型
20
20
21
- There are three types of built-in resolvers available on the ` compiler ` class:
21
+ 在 ` compiler ` 类中,提供了三种类型的内置解析器:
22
22
23
- - ` normal ` : Resolves a module via an absolute or relative path.
24
- - ` context ` : Resolves a module within a given context.
25
- - ` loader ` : Resolves a webpack [ loader] ( /loaders ) .
23
+ - ` normal ` : 通过绝对或相对路径解析模块。
24
+ - ` context ` : 在给定的上下文中解析模块。
25
+ - ` loader ` : 解析 webpack [ loader] ( /loaders ) 。
26
26
27
- Depending on need, any one of these built-in resolvers, that are used by the ` compiler ` ,
28
- can be customized via plugins:
27
+ 根据需要,任一个被使用在 ` compiler ` 中的内置解析器,
28
+ 可以通过插件进行定制:
29
29
30
30
``` js
31
31
compiler .resolverFactory .plugin (' resolver [type]' , resolver => {
@@ -35,20 +35,20 @@ compiler.resolverFactory.plugin('resolver [type]', resolver => {
35
35
});
36
36
```
37
37
38
- Where ` [type] ` is one of the three resolvers mentioned above.
38
+ 其中, ` [type] ` 是上述三个解析器之一。
39
39
40
- See the [ ` enhanced-resolve ` documentation] ( https://github.com/webpack/enhanced-resolve ) for a full list of hooks and their
41
- description.
40
+ 请参阅 [ ` enhanced-resolve ` documentation] ( https://github.com/webpack/enhanced-resolve ) 以获得钩子的完整列表以及它们的
41
+ 介绍。
42
42
43
43
44
- ## Configuration Options
44
+ ## 配置选项
45
45
46
- The resolvers mentioned above can also be customized via a configuration file
47
- with the [ ` resolve ` ] ( /configuration/resolve/ ) or [ ` resolveLoader ` ] ( /configuration/resolve/#resolveloader ) options. These options allow
48
- users to change the resolving behavior through a variety of options including
49
- through resolve ` plugins ` .
46
+ 上述解析器也可以
47
+ 利用 [ ` resolve ` ] ( /configuration/resolve/ ) or [ ` resolveLoader ` ] ( /configuration/resolve/#resolveloader ) 选项,通过配置文件进行定制。这些选项允许
48
+ 用户可以通过多种选项来更改解析行为,包括
49
+ 通过解析 ` plugins ` 。
50
50
51
- The resolver plugins, e.g. [ ` DirectoryNamedPlugin ` ] ( https://github.com/shaketbaby/directory-named-webpack-plugin ) , can be included
52
- directly in ` resolve.plugins ` rather than using directly in [ ` plugins ` configuration option] ( /configuration/plugins/#plugins ) .
51
+ 解析器插件,例如: [ ` DirectoryNamedPlugin ` ] ( https://github.com/shaketbaby/directory-named-webpack-plugin ) ,可以直接引入
52
+ 在 ` resolve.plugins ` ,而不是直接在 [ ` plugins ` configuration option] ( /configuration/plugins/#plugins ) 中使用。
53
53
54
- T> Note that the ` resolve ` configuration affects the ` normal ` and ` context ` resolvers while ` resolveLoader ` is used to modify the ` loader ` resolver.
54
+ T> 请注意, ` resolve ` 配置会影响 ` normal ` 解析器和 ` context ` 解析器,而“ ` resolveLoader ` 用于修改 ` loader ` 解析器。
0 commit comments