Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin apply not working for multi compiler #18236

Closed
nuintun opened this issue Mar 25, 2024 · 2 comments
Closed

Plugin apply not working for multi compiler #18236

nuintun opened this issue Mar 25, 2024 · 2 comments

Comments

@nuintun
Copy link
Contributor

nuintun commented Mar 25, 2024

Bug report

What is the current behavior?

Plugin apply not working for multi compiler.

If the current behavior is a bug, please provide the steps to reproduce.

import webpack from 'webpack';

const compiler = webpack([{
  // ...
}]);

for(const compiler of compiler.compilers) {
  // DefinePlugin
  new webpack.DefinePlugin(
    // ...
  ).apply(compiler);

  // EntryPlugin
  new webpack.EntryPlugin(
    // ...
  ).apply(compiler);

  // HotModuleReplacementPlugin
  new webpack.HotModuleReplacementPlugin(
    // ...
  ).apply(compiler);
}

All plugins DefinePlugin, EntryPlugin, HotModuleReplacementPlugin are not working.

Also see: https://github.com/webpack/webpack-dev-server/blob/edbc6e14cd96c6d652f8fef2d5fcfe6af829231a/lib/Server.js#L1639

What is the expected behavior?

Plugin apply not working for multi compiler.

Other relevant information:
webpack version: 5.91.0
Node.js version: 21.7.1
Operating System: Windows 11
Additional tools: N/A

@nuintun nuintun closed this as completed Mar 25, 2024
@nuintun nuintun reopened this Mar 25, 2024
@nuintun
Copy link
Contributor Author

nuintun commented Mar 25, 2024

This issues is very strange.

See: https://github.com/nuintun/webpack-dev-service/blob/63ef2873b654ad5a4473cd80a903a12bc605f493/src/server/index.ts#L47-L48

It's work fine.

const hotMiddleware = hot(compiler, hotOptions);
const devMiddleware = dev(compiler, options);

It's not work for multi compiler, but single compiler is ok.

const devMiddleware = dev(compiler, options);
const hotMiddleware = hot(compiler, hotOptions);

The dev module just a dev middleware for koa2 like webpack-dev-middleware.

@nuintun nuintun closed this as completed Mar 25, 2024
@nuintun
Copy link
Contributor Author

nuintun commented Mar 25, 2024

Resolved, dev start the watching, but plugins must be initialized before watching!

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

No branches or pull requests

1 participant