'Publish Webpack Library with Multiple Entry Points

I'm trying to use Webpack to publish a library that has multiple entrypoints. I have a webpack.config.js file like this:

const path = require("path");

module.exports = {
  entry: {
    alpha: "./src/library1.js",
    beta: "./src/library2.js",
  },
  output: {
    path: path.join(__dirname, "dist"),
    filename: "MyLibrary.[name].js",
    library: ["MyLibrary", "[name]"],
    libraryTarget: "umd",
    globalObject: "this",
  },
};

This works as advertised, and I get a dist folder with 2 files.

My question is, if I want to use this library, what do I put for the main property in package.json? My understanding is that main is a single entry point into your library, but I have 2 here (and I plan to have more).

Thanks for any help?



Solution 1:[1]

You can put an index file in the main, something like

index.js (put in main)

====

module.exports = {
  alpha: require("./dist/MyLibrary.library1.js"),
  beta: require("./dist/MyLibrary.library2.js");
}

module.js (put in module)

====

    export alpha from "./dist/MyLibrary.library1.js";
    export beta from "./dist/MyLibrary.library2.js";

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sumit