Skip to content

Commit 7d1f662

Browse files
arjendeblokTheDutchCoder
authored andcommitted
docs(concepts): Update plugins.md (#1871)
Update the plugins page in the concepts section to be compatible with webpack 4. Also adds a note about referencing the plugin name in camel-case when calling the `tap` method.
1 parent 6de8690 commit 7d1f662

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/content/concepts/plugins.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,18 @@ A webpack **plugin** is a JavaScript object that has an [`apply`](https://develo
2020
**ConsoleLogOnBuildWebpackPlugin.js**
2121

2222
```javascript
23-
function ConsoleLogOnBuildWebpackPlugin() {
24-
25-
};
26-
27-
ConsoleLogOnBuildWebpackPlugin.prototype.apply = function(compiler) {
28-
compiler.plugin('run', function(compiler, callback) {
29-
console.log("The webpack build process is starting!!!");
30-
31-
callback();
32-
});
33-
};
23+
const pluginName = 'ConsoleLogOnBuildWebpackPlugin';
24+
25+
class ConsoleLogOnBuildWebpackPlugin {
26+
apply(compiler) {
27+
compiler.hooks.run.tap(pluginName, compilation => {
28+
console.log("The webpack build process is starting!!!");
29+
});
30+
}
31+
}
3432
```
3533

36-
T> As a clever JavaScript developer you may remember the [`Function.prototype.apply`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply) method. Because of this method you can pass any function as plugin (`this` will point to the `compiler`). You can use this style to inline custom plugins in your configuration.
37-
34+
First parameter of the tap method of the compiler hook should be a camelized version of the plugin name. It is advisable to use a constant for this so it can be reused in all hooks.
3835

3936
## Usage
4037

src/utilities/markdown.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function parseAnchor(string) {
149149

150150
return {
151151
title: clean,
152-
id: clean.replace(/[^\w]+/g, '-').toLowerCase()
152+
id: clean.replace(/[^\w\u4e00-\u9fa5]+/g, '-').toLowerCase()
153153
};
154154
}
155155

0 commit comments

Comments
 (0)