For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/plugins/dll-reference-plugin.md.
close

DllReferencePlugin

DllReferencePlugin 将引用的模块链接到预构建的模块。

示例

基础示例

new rspack.DllReferencePlugin({
  // 这里引用的 manifest 文件应该是由 Dll 插件生成的
  manifest: require('../lib/manifest.json'),

  name: '[name]_dll_lib',
});

应用需要的依赖项将链接到由 DllPlugin 预构建的模块。

使用 Scope

通过配置 scope, dll 中的内容可以使用模块前缀的方式引用

new rspack.DllReferencePlugin({
  // 这里引用的 manifest 文件应该是由 Dll 插件生成的
  manifest: require('../lib/manifest.json'),

  name: '[name]_dll_lib',

  scope: 'xyz',
});

举例来说,通过 require('xzy/abc') 可以获取预构建模块中 abc 模块。

选项

  • 类型:
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

  • 类型: DllReferencePluginOptionsContent
  • 默认值: undefined

直接提供从模块请求到模块元数据的映射。使用这种形式代替 manifest 时,必须配置 name

context

  • 类型: string
  • 默认值: undefined

设置将模块请求与 manifestcontent 中的键进行匹配时使用的绝对 context。使用通过自定义 DllPlugin.context 生成的 manifest 时,应将该选项设置为相同的路径。

extensions

  • 类型: string[]
  • 默认值: ['', '.js', '.json', '.wasm']

配置 scope 后,设置解析 DLL bundle 中模块时使用的扩展名。

manifest

  • 类型: string | DllReferencePluginOptionsManifest
  • 默认值: undefined

提供 manifest 对象,或由 DllPlugin 生成的 JSON manifest 文件的绝对路径。该选项与 content 二选一。

name

  • 类型: string
  • 默认值: manifest.name

设置 DLL 暴露时使用的 external 名称。直接提供 content 时,该选项为必填项。

scope

  • 类型: string
  • 默认值: undefined

设置访问 DLL 内容时使用的模块前缀。

sourceType

  • 类型: DllReferencePluginOptionsSourceType
  • 默认值: manifest.type;未提供类型时为 'var'

设置 DLL 的暴露方式,对应其 library type。

type

  • 类型: 'require' | 'object'
  • 默认值: 'require'

控制如何使用 DLL bundle 的导出。

当依赖被引用的时候,插件通过 dll manifest 文件将依赖名和预打包的模块链接起来。

本页改编自 webpack 文档,遵循 CC BY 4.0,且已作修改。