Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
webpack 5 always include re exported module into main.js

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!