Skip to content

docs: add AssetLoggerPlugin example to writing-a-plugin guide#7988

Merged
alexander-akait merged 7 commits into
webpack:mainfrom
raj-sapalya:add-asset-logger-plugin-example
Mar 12, 2026
Merged

docs: add AssetLoggerPlugin example to writing-a-plugin guide#7988
alexander-akait merged 7 commits into
webpack:mainfrom
raj-sapalya:add-asset-logger-plugin-example

Conversation

@raj-sapalya
Copy link
Copy Markdown
Contributor

This PR adds a minimal Webpack plugin example (AssetLoggerPlugin) to the "Writing a Plugin" guide.

The example demonstrates how to use the emit hook to log generated assets during compilation. This helps beginners understand Webpack plugin hooks and plugin architecture.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webpack-js-org Ready Ready Preview, Comment Mar 12, 2026 6:11pm

Request Review

@raj-sapalya
Copy link
Copy Markdown
Contributor Author

raj-sapalya commented Mar 12, 2026

Hello maintainer.... This PR adds a simple plugin example to help beginners
understand Webpack plugin hooks. Please let me know if any changes are needed.

```js
class AssetLoggerPlugin {
apply(compiler) {
compiler.hooks.emit.tap("AssetLoggerPlugin", (compilation) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emit is deprecated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback! I’ve updated the example to use the
thisCompilation and processAssets hooks instead of the deprecated emit hook.

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix lint problems

(assets) => {
console.log("Generated assets:");
for (const assetName of Object.keys(assets)) {
console.log(assetName);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webpack has own logger interface please use it here

Copy link
Copy Markdown
Contributor Author

@raj-sapalya raj-sapalya Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback!
I’ve updated the AssetLoggerPlugin example to use the Webpack logger interface ( compilation.getLogger ) instead of console.log . The plugin now logs all generated assets using Webpack's official logger.
Please let me know if any further improvements are needed.

@alexander-akait alexander-akait merged commit c4f0a59 into webpack:main Mar 12, 2026
8 of 9 checks passed
@raj-sapalya raj-sapalya deleted the add-asset-logger-plugin-example branch March 14, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants