Volt.Config (Volt v0.11.1)

Copy Markdown View Source

Read Volt configuration from application environment.

Flat config (single app)

All config lives under the :volt application key in config/config.exs:

# config/config.exs
config :volt,
  entry: "assets/js/app.ts",
  target: :es2020,
  external: ~w(phoenix phoenix_html phoenix_live_view),
  aliases: %{
    "@" => "assets/src",
    "@components" => "assets/src/components"
  },
  plugins: [],
  tailwind: [
    css: "assets/css/app.css",
    sources: [
      %{base: "lib/", pattern: "**/*.{ex,heex}"},
      %{base: "assets/", pattern: "**/*.{vue,ts,tsx}"}
    ]
  ]

# config/dev.exs
config :volt, :server,
  prefix: "/assets",
  watch_dirs: ["lib/"]

Named profiles (umbrella / multi-web apps)

Use a named profile to configure multiple independent Volt instances:

# config/config.exs
config :volt, :my_app_web,
  entry: "apps/my_app_web/assets/js/app.js",
  outdir: "apps/my_app_web/priv/static/assets",
  tailwind: [
    css: "apps/my_app_web/assets/css/app.css",
    sources: [
      %{base: "apps/my_app_web/lib/", pattern: "**/*.{ex,heex,eex}"}
    ]
  ],
  server: [watch_dirs: ["apps/my_app_web/lib/"]]

Pass the profile name to Mix tasks and the plug:

mix volt.build my_app_web --tailwind
mix volt.dev my_app_web --tailwind

plug Volt.DevServer, root: "assets", profile: :my_app_web

CLI flags and plug options override config values.

Source maps

The :sourcemap option controls production source map generation:

  • true — write .map files and append //# sourceMappingURL (default)
  • :hidden — write .map files but omit the URL comment (for error tracking services)
  • false — no source maps

Manual chunks

The :chunks option controls manual chunk splitting:

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

Bare specifiers match package names in node_modules. Path patterns match against the full module path.

tsconfig.json paths

Volt automatically reads compilerOptions.paths from tsconfig.json in the project root and merges them into aliases. Explicitly configured aliases take precedence over tsconfig paths.

Summary

Functions

Read the full build config, merged with defaults.

Read dev server config, merged with defaults.

Read Tailwind config.

Functions

build(profile_or_overrides \\ [])

@spec build(atom() | keyword()) :: map()

Read the full build config, merged with defaults.

Accepts an optional profile atom as the first argument. When given, reads from Application.get_env(:volt, profile) and merges it on top of flat config and defaults.

overrides (from CLI flags or function opts) take precedence over all config sources.

Automatically reads compilerOptions.paths from tsconfig.json and merges them into aliases. Explicit aliases override tsconfig paths.

build(profile, overrides)

@spec build(
  atom() | nil,
  keyword()
) :: map()

server(profile_or_overrides \\ [])

@spec server(atom() | keyword()) :: map()

Read dev server config, merged with defaults.

When a profile is given, reads the :server key from within that profile's config, falling back to the global :server config.

server(profile, overrides)

@spec server(
  atom() | nil,
  keyword()
) :: map()

tailwind(profile \\ nil)

@spec tailwind(atom() | nil) :: keyword()

Read Tailwind config.

When a profile is given, reads the :tailwind key from within that profile's config, falling back to the global :tailwind config.