Volt.ChunkGraph (Volt v0.10.1)

Copy Markdown View Source

Build a chunk graph from module dependencies.

Splits modules into chunks based on dynamic import boundaries:

  • The entry chunk contains all modules reachable via static imports
  • Each dynamic import() creates a new async chunk
  • Modules shared between multiple chunks are extracted into common chunks

Chunk types

  • :entry — the main bundle, loaded synchronously
  • :async — loaded on demand via dynamic import
  • :common — shared code extracted to avoid duplication
  • :manual — user-defined chunk via chunks config

Manual chunks

Users can control chunk boundaries via config:

config :volt,
  chunks: %{
    "vendor" => ["vue", "vue-router", "pinia"],
    "ui" => ["assets/src/components"]
  }

Patterns match module paths: bare specifiers match package names in node_modules, while path patterns match against the full module path.

Summary

Types

chunk()

@type chunk() :: %{
  id: String.t(),
  type: :entry | :async | :common | :manual,
  modules: [String.t()],
  imports: [String.t()]
}

Functions

build(entry_path, modules, dep_map, opts \\ [])

Build chunks from a module graph.

modules is a list of {abs_path, label, source} tuples in dependency order. dep_map maps abs_path => %{static: [abs_path], dynamic: [abs_path]}. entry_path is the absolute path of the entry file.

Options

  • :manual_chunks — map of chunk name to list of patterns, e.g. %{"vendor" => ["vue", "vue-router"]}