Skip to content

Commit 49600b2

Browse files
Merge pull request webpack#158 from jeffrygan/cn
translation
2 parents 76468d4 + 8cb702d commit 49600b2

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

content/pluginsapi/tapable.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,39 @@ contributors:
77
- e-cloud
88
---
99

10-
[Tapable](https://github.com/webpack/tapable) is small library that allows you to add and apply plugins to a javascript module.
11-
It can be inherited or mixed in to other modules. It is similar to NodeJS's `EventEmitter` class, focusing on custom event emission and manipulation.
12-
However, in addition to this, `Tapable` allows you to have access to the "emittee" or "producer" of the event through callbacks arguments.
10+
[Tapable](https://github.com/webpack/tapable)是一个小型库,能够让我们为javascript模块添加并应用插件。
11+
它可以被其它模块继承或混合。它类似于NodeJS的 `EventEmitter` 类,专注于自定义事件的发射和操作。
12+
除此之外, `Tapable` 允许你通过回调函数的参数访问事件的生产者。
1313

14-
`Tapable` has four groups of member functions:
14+
`Tapable` 有四组成员函数:
1515

16-
* `plugin(name:string, handler:function)` - This allows a custom plugin to register into a **Tapable instance**'s event.
17-
This acts as the same as `on()` of `EventEmitter`, for registering a handler/listener to do something when the signal/event happens.
16+
* `plugin(name:string, handler:function)` - 这个方法允许给**Tapable实例**事件注册一个自定义插件。
17+
这个操作类似于 `EventEmitter``on()`, 注册一个处理函数/监听器到某个信号/事件发生时执行。
1818

19-
* `apply(…pluginInstances: (AnyPlugin|function)[])` - `AnyPlugin` should be subclass of [AbstractPlugin](https://github.com/webpack/webpack/blob/master/lib/AbstractPlugin.js), or a class (or object, rare case) has an `apply` method, or just a function with some registration code inside.
20-
This method is just to **apply** plugins' definition, so that the real event listeners can be registered into the **Tapable instance**'s registry.
19+
* `apply(…pluginInstances: (AnyPlugin|function)[])` - `AnyPlugin` [AbstractPlugin](https://github.com/webpack/webpack/blob/master/lib/AbstractPlugin.js)的子类, 或者是一个有 `apply` 方法的类(少数情况下是个对象),或者只是一个有注册代码的函数。
20+
这个方法只是 **apply** 插件的定义,所以正真的事件监听器会被注册到**Tapable实例**的注册表。
2121

22-
* `applyPlugins*(name:string, …)` - The **Tapable instance** can apply all the plugins under a particular hash using these functions.
23-
These group of method act like `emit()` of `EventEmitter`, to control the event emission meticulously with various strategy for various use cases.
22+
* `applyPlugins*(name:string, …)` - **Tapable instance** ????
23+
这些方法执行类似于 `EventEmitter``emit()`, 可以针对不同的使用情况采用不同的策略控制事件发射。
2424

25-
* `mixin(pt: Object)` - a simple method to extend `Tapable`'s prototype as a mixin rather than inheritance.
25+
* `mixin(pt: Object)` - 一个简单的方法能够以混合的方式扩展 `Tapable` 的原型,而非继承。
2626

27-
The different `applyPlugins*` methods cover the following use cases:
27+
不同的 `applyPlugins*` 方法对应以下使用情况:
2828

29-
* Plugins can run serially
29+
* 串行执行插件
3030

31-
* Plugins can run in parallel
31+
* 并行执行插件
3232

33-
* Plugins can run one after the other but taking input from the previous plugin (waterfall)
33+
* 插件一个接一个的执行,并且每个插件接收上一个插件的返回值(瀑布)
3434

35-
* Plugins can run asynchronously
35+
* 异步执行插件
3636

37-
* Quit runing plugins on bail: that is once one plugin returns non-`undefined`, jump out of the run flow and return *the return of that plugin*. This sounds like `once()` of `EventEmitter` but is totally different.
37+
* 保护模式终止插件执行: 一旦某个插件返回 non-`undefined` ,会退出运行流程并返回 *这个插件的返回值*。这看起来像 `EventEmitter``once()`,但他们是完全不同的。
3838

39-
## Example
40-
One of webpack's **Tapable instances**, [Compiler](./compiler), is responsible for compiling the webpack configuration object and returning a [Compilation](./compilation) instance. When the Compilation instance runs, it creates the required bundles.
39+
## 示例
40+
webpack中有个Tapable实例 [Compiler](./compiler), 它的作用是编译webpack的配置对象,并返回[Compilation](./compilation)实例。当Compilation实例运行时,它会创建所需的包。
4141

42-
See below is a simplified version of how this looks using `Tapable`.
42+
下面是一个使用 `Tapable` 的小例子。
4343

4444
**node_modules/webpack/lib/Compiler.js**
4545

@@ -51,7 +51,7 @@ function Compiler() {
5151
Compiler.prototype = Object.create(Tapable.prototype);
5252
```
5353

54-
Now to write a plugin on the compiler,
54+
接着写一个编译器的插件
5555

5656
**my-custom-plugin.js**
5757

@@ -62,7 +62,7 @@ CustomPlugin.prototype.apply = function(compiler) {
6262
}
6363
```
6464

65-
The compiler executes the plugin at the appropriate point in its lifecycle by
65+
这个编译器会依下面的代码在合适的生命周期点执行插件
6666

6767
**node_modules/webpack/lib/Compiler.js**
6868

@@ -72,4 +72,4 @@ this.apply*("emit",options) // will fetch all plugins under 'emit' name and run
7272

7373
***
7474

75-
> 原文:https://webpack.js.org/pluginsapi/tapable/
75+
> 原文:https://webpack.js.org/pluginsapi/tapable/

0 commit comments

Comments
 (0)