Webpack Plugin: How to add dynamically a Module to the main Chunk?

OK, So I've managed to collect some pieces of code from several plugins, and the winning solution is to inject a loader to some fake import file, in that loader load the entire js code to the main bundle, and put some placeholder for the results from optimize-chunk-assets phase.

After that, in optimize-chunk-assets, you can find the relevant chunk, and use ReplaceSource to find & replace the placeholder.

For inspiration, you can checkout that plugin.