Search code examples
javascriptnode.jswebpackwebpack-2

How to rename output.library option for each entry point in Webpack?


I'd like to compile multiple entry points with Webpack, but it applies the same library name to all of the output bundles. I'd like for each bundle to have a different library name.

For example, here's part of my webpack.config.js:

entry: {
    app: "./src/app.tsx",
    editor: "./src/modes/editor.ts",
},

output: {
    path: path.resolve(__dirname, '..', 'build'),
    filename: "[name].js",
    libraryTarget: 'amd',
    library: 'app',
},

Each bundle uses the output.library option ("app"), but I want each bundle to use a different library name.

How can this be done?


Solution

  • Ah, it is not documented on the website, but this example shows how: https://github.com/webpack/webpack/tree/master/examples/multi-part-library

    Basically, just put [name] in there: library: '[name]' (similar to the filename option).