I am using the example for multipart lib from the docs: https://github.com/webpack/webpack/tree/master/examples/multi-part-library
I am outputting them with the following config:
//webpack.config.js
var path = require("path");
module.exports = {
// mode: "development || "production",
experiments: {
outputModule: true,
},
entry: {
index: "./src/index",
alpha: "./src/alpha",
beta: "./src/beta",
omega: "./src/omega",
},
output: {
clean: true,
path: path.join(__dirname, "dist"),
filename: "MyLibrary.[name].js",
// library: ["MyLibrary", "[name]"],
libraryTarget: "module",
chunkFormat: 'module',
},
};
What I am not getting is that why the re exported modules are being included in the main. All I want is the main to a single point where I can import any of the modules I don't want to bundle them into it.
Just want to keep it as it is, but packaged with webpack. Similar to what you can do wit esbuild where you have the index.js but the re exported modules are not included in the main/index. ex: fp-ts esm bundle.
//index.js
export { default as alpha } from './alpha'
export { default as beta } from './beta'
export * from './omega'
Any ideas how I can achieve the same with webpack 5?
EDIT: After a lot of checking and testing I came to realize that I think webpack does that because no matter re exporting the modules all of them would be downloaded anyways in the browser. Which is ok. But I would still like to know how to avoid that and make sure that webpack re use the already build modules instead of adding them in the main.js.