File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,20 +31,24 @@ A plugin for webpack consists of:
3131class 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 }
You can’t perform that action at this time.
0 commit comments