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