WebPack - Dependency

> (World Wide) Web - (W3|WWW) > Web - Building and Shipping > Web - WebPack

1 - About

Advertising

3 - Management

3.1 - Exclude

To exclude a package with webpack, you have to:

In development mode, it allows to avoid bundling all dependencies, which allows browsers to cache those libraries between builds.

Example with JQuery that is available on the global variable 'jQuery'. The below configuration tells WebPack to map the import (for instance for a commonjs module - require(“jquery”)) to the global variable jQuery

webpack.config.js
externals: {
        // JQuery is a peer dependency (external) and available globally with the jQuery variable
        jquery: "jQuery"
}

Other examples:

externals: [
  "react": "React",
  "react-dom": "ReactDOM"
  'library/one',
  'library/two',
  // Everything that starts with "library/"
  /^library\/.+$/
]

See https://webpack.js.org/configuration/externals/