Skip to content

Interface: SourceDescription ​

Extends ​

Properties ​

code ​

  • Type: string

declaredModuleSize? ​

  • Type: number
  • Optional

The module's size in bytes. Size-based code splitting uses it instead of the size of the module's code.

This is useful when a plugin emits output for each chunk from the modules in it, and that output is not in the modules' code. For example, with build.cssCodeSplit: true, Vite emits a stylesheet for each JS chunk from the CSS of the style modules the chunk contains, while the code of a style module is empty or only a class-name map.

Example ​

js
transform(code, id) {
  if (isCss(id)) {
    return { code, declaredModuleSize: Buffer.byteLength(code) + Buffer.byteLength(css) }
  }
}

description? ​

  • Type: string | null
  • Optional

A short, human-readable description of the module.

This is useful for virtual modules, whose ids (e.g. \0vite/modulepreload-polyfill.js) do not convey their purpose on their own.

Example ​

js
function polyfillPlugin() {
  return {
    name: 'vite:modulepreload-polyfill',
     load: {
       filter: { id: /^\0vite/modulepreload-polyfill\.js$/ },
       handler(id) {
         return {
           code: '',
           description: 'A polyfill for `link` tag with `rel="modulepreload"`',
         };
       }
     },
  };
}

Inherited from ​

ModuleOptions.description


map? ​

The source map for the transformation.

If the transformation does not move code, you can preserve existing sourcemaps by setting this to null.

See Source Code Transformations section for more details.


meta? ​

See Custom module meta-data section for more details.

Inherited from ​

ModuleOptions.meta


moduleSideEffects? ​

  • Type: ModuleSideEffects
  • Optional

Indicates whether the module has side effects to Rolldown.

  • If false is set, Rolldown treats the module as side-effect-free. It may drop a bare import or resolve a re-export directly to its defining module.
  • If true is set, Rolldown analyzes bundled modules for side effects, bypassing the treeshake.moduleSideEffects option and package sideEffects metadata. External modules use Rolldown's default side-effect assumptions.
  • If "no-treeshake" is set, treeshaking will be disabled for this module, and this module will be included in one of the chunks even if it is empty.

The precedence of this option is as follows (highest to lowest):

  1. transform hook's returned moduleSideEffects option
  2. load hook's returned moduleSideEffects option
  3. resolveId hook's returned moduleSideEffects option
  4. treeshake.moduleSideEffects, when the option supplies a verdict for the module
  5. sideEffects field in package.json for bundled modules. Rolldown uses this field only when its own resolver resolved the module. This is also the case when a resolveId hook returned a this.resolve result that Rolldown's resolver gave. When a hook returned its own id, such as a virtual module, Rolldown does not use the field.
  6. Static analysis for bundled modules and Rolldown's default side-effect assumptions for external modules

this.getModuleInfo(id).moduleSideEffects and this.resolve(id).moduleSideEffects report the effective setting. They report true when Rolldown falls back to statement analysis, regardless of the analysis result. An external module that falls back to the default assumption of side effects also reports true when no hook supplies a value.

With treeshake: false, a hook's true keeps tree-shaking disabled. The APIs report true unless a hook returns false or "no-treeshake".

Inherited from ​

SpecifiedModuleOptions.moduleSideEffects


moduleType? ​


packageJsonPath? ​

  • Type: string | null
  • Optional

Inherited from ​

ModuleOptions.packageJsonPath

Was this page helpful?