Skip to content

Type Alias: ExperimentalInlineCommonChunksOptions ​

  • Type: { exclude?: StringOrRegExp | ((id) => boolean | void | undefined) | (StringOrRegExp | ((id) => boolean | void | undefined))[]; maxSize?: number; }
  • Experimental

Options for codeSplitting.experimentalInlineCommonChunks.

Small common chunks produced by automatic code splitting are replaced by a factory function that is copied into the chunks reading them (a chunk whose static dependency already carries the factory uses that copy). A registry in the runtime chunk makes sure the chunk's modules keep one state, one execution and one set of export identities across all copies, so no entry downloads code it could not reach with the option off.

Before enabling it, check the plugins and code shapes that see a chunk's modules as one file:

  • A module of an inlined chunk appears in the moduleIds and modules of every chunk that prints a copy, so a plugin that asks which chunk owns a module gets several answers. Vite's CSS plugin, for example, emits a style module's CSS from every chunk whose moduleIds list it; a Vite build passes exclude: /\.(css|scss|sass|less|styl|stylus|pcss|postcss|sss)(\?|$)/ so chunks holding styles stay files.
  • A renderChunk hook whose rewrite yields different values in different directories makes the copies differ, and the first chunk to run decides which text every reader sees; exclude the modules concerned. Vite's asset URLs under a relative base resolve through import.meta.url to the same URL from every copy and are not affected.
  • The option turns strictExecutionOrder on when it is omitted. Strict execution order has an open issue with top-level await inside static import cycles (rolldown/rolldown#9548), so run the application under strictExecutionOrder: true before adding this option.
  • Addons (banner, intro, outro and footer), including plugin hooks, apply to emitted files. An inlined chunk shares the addon bindings of the file that registers its factory first. Exclude modules that depend on separate file-local bindings or addon initialization order.
  • A chunk that prints an inlined chunk names both sets of modules together, so a function or class in either can get a $1-style suffix when the other declares the same name, and the .name of an inlined chunk's function or class depends on which chunk loads first (under minify, the mangled name does too). output.keepNames keeps every name.

This feature is experimental. Its behavior and option shape may change in any release.

Properties ​

exclude? ​

  • Type: StringOrRegExp | ((id) => boolean | void | undefined) | (StringOrRegExp | ((id) => boolean | void | undefined))[]
  • Optional

A matcher for module ids, or an array of them: a string (matched as a regular expression), a RegExp, or a function, each applied like test. A common chunk is kept as a file when any of its modules matches any matcher.


maxSize? ​

  • Type: number
  • Optional

Common chunks whose pre-render size (the sum of the transformed source sizes of their modules, in bytes) is strictly smaller than this value are candidates for inlining. Use Infinity to remove the size limit.

A value greater than 0 requires output.format: 'es', an explicit preserveEntrySignatures: false and code splitting, and it turns on strictExecutionOrder when that option is omitted. output.strictExecutionOrder: false is an error, output.preserveModules, experimental.devMode and experimental.onDemandWrapping must be off.

Default ​

ts
0

Was this page helpful?