Skip to content

Commit 67c9963

Browse files
authored
docs: migrate to new hooks
1 parent e1383a8 commit 67c9963

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/content/contribute/writing-a-plugin.mdx

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,24 @@ A plugin for webpack consists of:
3131
class MyExampleWebpackPlugin {
3232
// Define `apply` as its prototype method which is supplied with compiler as its argument
3333
apply(compiler) {
34-
// Specify the event hook to attach to
35-
compiler.hooks.emit.tapAsync(
34+
// Hook into the compilation
35+
compiler.hooks.thisCompilation.tap(
3636
"MyExampleWebpackPlugin",
37-
(compilation, callback) => {
38-
console.log("This is an example plugin!");
39-
console.log(
40-
"Here’s the `compilation` object which represents a single build of assets:",
41-
compilation,
37+
(compilation) => {
38+
// Specify the asset processing hook
39+
compilation.hooks.processAssets.tap(
40+
{
41+
name: "MyExampleWebpackPlugin",
42+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
43+
},
44+
(assets) => {
45+
console.log("This is an example plugin!");
46+
console.log(
47+
"Here’s the `compilation` object which represents a single build of assets:",
48+
compilation,
49+
);
50+
},
4251
);
43-
44-
// Manipulate the build using the plugin API provided by webpack
45-
compilation.addModule(/* ... */);
46-
47-
callback();
4852
},
4953
);
5054
}

0 commit comments

Comments
 (0)