Skip to content

Commit 122e036

Browse files
author
Pavithra K
committed
Adds plugin anatomy
1 parent 1556a44 commit 122e036

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

content/concepts/plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function ConsoleLogOnBuildWebpackPlugin() {
2222
};
2323

2424
ConsoleLogOnBuildWebpackPlugin.prototype.apply = function(compiler) {
25-
compiler.plugin('run', function(compiler, callback) {
25+
compiler.plugin('run', function(compilation, callback) {
2626
console.log("The webpack build process is starting!!!");
2727

2828
callback();

content/pluginsapi/index.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ For more information on `Tapable` visit the [tapable repository](https://github.
1717

1818
## Creating a Plugin
1919

20-
20+
A plugin for `webpack` consists of
21+
22+
- A named JavaScript function.
23+
- Defines `apply` method in it's prototype.
24+
- Specifies webpack's event hook to attach itself.
25+
- Manipulates webpack internal instance specific data.
26+
- Invokes webpack provided callback after functionality is complete.
27+
28+
```javascript
29+
// A named JavaScript function.
30+
function MyExampleWebpackPlugin() {
31+
32+
};
33+
34+
// Defines `apply` method in it's prototype.
35+
MyExampleWebpackPlugin.prototype.apply = function(compiler) {
36+
// Specifies webpack's event hook to attach itself.
37+
compiler.plugin('webpacksEventHook', function(compilation /* Manipulates webpack internal instance specific data. */, callback) {
38+
console.log("This is an example plugin!!!");
39+
40+
// Invokes webpack provided callback after functionality is complete.
41+
callback();
42+
});
43+
};
44+
```
2145

2246
### Different Plugin Shapes

0 commit comments

Comments
 (0)