DllReferencePlugin
The DllReferencePlugin is used to reference the dll-only-bundle to require pre-built dependencies.
Examples
Basic example
new rspack.DllReferencePlugin({
// Manifest should be generated by DllPlugin
manifest: require('../lib/manifest.json'),
name: '[name]_dll_lib',
});
Application require dependencies will reference to pre-built using DllPlugin.
With scope
The content of the dll is accessible under a module prefix when set scope.
new rspack.DllReferencePlugin({
// Manifest should be generated by DllPlugin
manifest: require('../lib/manifest.json'),
name: '[name]_dll_lib',
scope: 'xyz',
});
Access via require('xzy/abc'), you can require abc from another pre-built lib.
Options
type DllReferencePluginOptionsContent = {
/**
* Module info.
*/
[k: string]: {
/**
* Meta information about the module.
*/
buildMeta?: {
[k: string]: any;
};
/**
* Information about the provided exports of the module.
*/
exports?: string[] | true;
/**
* Module ID.
*/
id?: string | number;
};
};
type DllReferencePluginOptionsManifest = {
/**
* The mappings from module specifier to module info.
*/
content: DllReferencePluginOptionsContent;
/**
* The name where the dll is exposed (external name).
*/
name?: string;
/**
* The type how the dll is exposed (external type).
*/
type?: DllReferencePluginOptionsSourceType;
};
/**
* The type how the dll is exposed (external type).
*/
type DllReferencePluginOptionsSourceType =
| 'var'
| 'assign'
| 'this'
| 'window'
| 'global'
| 'commonjs'
| 'commonjs2'
| 'commonjs-module'
| 'amd'
| 'amd-require'
| 'umd'
| 'umd2'
| 'jsonp'
| 'system';
type DllReferencePluginOptions =
| {
/**
* Context of requests in the manifest (or content property) as absolute path.
*/
context?: string;
/**
* Extensions used to resolve modules in the dll bundle (only used when using 'scope').
*/
extensions?: string[];
/**
* An object containing content and name or a string to the absolute path of the JSON manifest to be loaded upon compilation.
*/
manifest: string | DllReferencePluginOptionsManifest;
/**
* The name where the dll is exposed (external name, defaults to manifest.name).
*/
name?: string;
/**
* Prefix which is used for accessing the content of the dll.
*/
scope?: string;
/**
* How the dll is exposed (libraryTarget, defaults to manifest.type).
*/
sourceType?: DllReferencePluginOptionsSourceType;
/**
* The way how the export of the dll bundle is used.
*/
type?: 'require' | 'object';
}
| {
/**
* The mappings from module specifier to module info.
*/
content: DllReferencePluginOptionsContent;
/**
* Context of requests in the manifest (or content property) as absolute path.
*/
context?: string;
/**
* Extensions used to resolve modules in the dll bundle (only used when using 'scope').
*/
extensions?: string[];
/**
* The name where the dll is exposed (external name).
*/
name: string;
/**
* Prefix which is used for accessing the content of the dll.
*/
scope?: string;
/**
* How the dll is exposed (libraryTarget).
*/
sourceType?: DllReferencePluginOptionsSourceType;
/**
* The way how the export of the dll bundle is used.
*/
type?: 'require' | 'object';
};
content
- Type:
DllReferencePluginOptionsContent
- Default:
undefined
Provides the mappings from module requests to module metadata directly. When this form is used instead of manifest, name is required.
context
- Type:
string
- Default:
undefined
Sets the absolute context used to match module requests against keys in manifest or content. When using a manifest generated with a custom DllPlugin.context, set this option to the same path.
extensions
- Type:
string[]
- Default:
['', '.js', '.json', '.wasm']
Sets the extensions used to resolve modules in the DLL bundle when scope is configured.
manifest
- Type:
string | DllReferencePluginOptionsManifest
- Default:
undefined
Provides either a manifest object or the absolute path to a JSON manifest generated by DllPlugin. Use this option instead of content.
name
- Type:
string
- Default:
manifest.name
Sets the external name under which the DLL is exposed. It is required when content is provided directly.
scope
- Type:
string
- Default:
undefined
Sets the module prefix used to access content from the DLL.
sourceType
- Type:
DllReferencePluginOptionsSourceType
- Default:
manifest.type, or 'var' when no type is provided
Sets how the DLL is exposed, corresponding to its library type.
type
- Type:
'require' | 'object'
- Default:
'require'
Controls how exports from the DLL bundle are consumed.
This plugin references a dll manifest file to map dependency names to module ids, then require them as needed.
This page is adapted from webpack documentation under the CC BY 4.0, with modifications.