bugfix: Fix a bug that caused conflicting assets when adding a child compiler (#78011)
fixes #76930 ## Summary Fixes an issue where using a Webpack plugin that creates child compilers in a Next.js project could result in asset emission conflicts. ## Description Starting from [vercel/next.js#75927](https://github.com/vercel/next.js/pull/75927), Next.js uses compilation.emitAsset to emit assets. However, emitAsset throws an error when attempting to emit an asset with the same name and identical content more than once. This behavior is defined in Webpack's implementation: https://github.com/webpack/webpack/blob/70e3d9d5dbd3548431b8878dead4647beff5c14f/lib/Compilation.js#L4615-L4628 When a plugin hooks into the compilation phase, it also runs for child compilers. This can lead to duplicated asset emission when using plugins that spawn child compilers, such as [vanilla-extract](https://github.com/vanilla-extract-css/vanilla-extract/blob/c66be53d600802b2922da1d6034e2a5ff3fbbcae/packages/webpack-plugin/src/compiler.ts#L85-L89). To prevent this, we now use the thisCompilation hook instead of compilation, which ensures that the plugin only applies to the main compilation and not to any child compilers. --------- Co-authored-by:Tobias Koppers <tobias.koppers@googlemail.com> Co-authored-by:
Will Binns-Smith <wbinnssmith@gmail.com>
Showing
Please
register
or
sign in
to comment