javascriptwebpackwebpack-externals

Webpack externals configuration - root key


What does it mean and what is root for in Webpack externals configuration?

module.exports = {
    output: {
        libraryTarget: "umd"
    },
    externals: [
        "add",
        {
            "subtract": {
                root: "subtract",
                commonjs2: "./subtract",
                commonjs: ["./math", "subtract"],
                amd: "subtract"
            }
        }
    ]
} 

Solution

  • Check the answer here:

    webpack umd lib and external files

    Basically it applies to UMD modules and it is used to solve global dependencies when your module is loaded using the <script> tag or well a CDN repo.