ExternalsPlugin
This plugin allows you to specify external dependencies that should not be bundled into the output files. This is particularly useful for libraries that are already available globally or managed by other scripts.
The externalsType
and externals
configurations leverage the plugin internally. Therefore, you can utilize the respective functionality directly through these configuration options without needing to use the plugin separately.
new rspack.ExternalsPlugin(type, externals);
Options
type
Type:
type ExternalsType =
| 'var'
| 'module'
| 'assign'
| 'this'
| 'window'
| 'self'
| 'global'
| 'commonjs'
| 'commonjs2'
| 'commonjs-module'
| 'commonjs-static'
| 'amd'
| 'amd-require'
| 'umd'
| 'umd2'
| 'jsonp'
| 'system'
| 'promise'
| 'import'
| 'script'
| 'node-commonjs';
Specifies the default type for the externals
.
For more details, refer to externalsType.
externals
Type:
type Externals = ExternalItem[] | ExternalItem;
type ExternalItem =
| RegExp
| string
| (
| ((
data: ExternalItemFunctionData,
callback: (err?: Error | null, result?: ExternalItemValue) => void,
) => void)
| ((data: ExternalItemFunctionData) => Promise<ExternalItemValue>)
);
type ExternalItemValue =
| string[]
| boolean
| string
| {
[k: string]: any;
};
type ExternalItemFunctionData = {
context?: string;
contextInfo?: ModuleFactoryCreateDataContextInfo;
getResolve?: (
options?: ResolveOptions,
) =>
| ((
context: string,
request: string,
callback: (err?: Error, result?: string) => void,
) => void)
| ((context: string, request: string) => Promise<string>);
request?: string;
};
type ModuleFactoryCreateDataContextInfo = {
issuer: string;
compiler: string;
};
Prevent bundling of certain import
ed packages and instead retrieve these external dependencies at runtime.
For more details, refer to externals.