output.externals

  • Type:
type Externals =
  | string
  | object
  | function
  | RegExp
  | Array<string | object | function | RegExp>;
  • Default: undefined

At build time, prevent some import dependencies from being packed into bundles in your code, and instead fetch them externally at runtime.

For more information, please see: Rspack Externals.

Example

Exclude the react-dom dependency from the build product. To get this module at runtime, the value of react-dom will globally retrieve the ReactDOM variable.

export default {
  output: {
    externals: {
      'react-dom': 'ReactDOM',
    },
  },
};
TIP

If output.target is web-worker, externals will not take effect. This is because the Web Worker environment can not access global variables.

ON THIS PAGE