Skip to content

Building for Production

vantris build produces an optimised production bundle in outDir. It's powered by Rolldown — tree shaking, minification, code splitting, and content-hashed output — but Rolldown is never exposed: every option is Vantris-owned.

bash
vantris build          # → dist/

What a build does

  1. Cleans outDir (guarded so it can never remove anything outside it).
  2. Analyses index.html for <script type="module"> entries (multiple supported).
  3. Bundles with Rolldown — tree shaking, minification, code splitting.
  4. Rewrites dist/index.html to point at the hashed output.
  5. Copies public/ verbatim.

The mode defaults to production. Override with --mode.

HTML processing

The build treats index.html as the entry graph. What gets processed:

  • JS-imported assets (import url from "./logo.svg") → hashed files with absolute URLs derived from base.
  • CSS (import "./style.css") → processed with lightningcss, emitted as a hashed .css with a <link> injected. Includes url() rewriting, @import inlining, CSS Modules, Sass/Less, PostCSS, and CSS code splitting for lazy chunks. See CSS.
  • HTML src/href in <link>/<img>/<script> that point into rootDir → hashed and rewritten. Public and external references are left untouched.

Output naming

Built files are content-hashed by default so they cache forever and bust on change. The patterns are configurable and each accepts a string pattern or a function:

ts
export default defineConfig({
  build: {
    assetsDir: "assets", // drives the defaults below
    entryFileNames: "assets/[name]-[hash].js",
    chunkFileNames: "assets/[name]-[hash].js",
    assetFileNames: "assets/[name]-[hash][extname]",
  },
});
ts
build: {
  entryFileNames: (chunk) => `js/${chunk.name}.[hash].js`,
  assetFileNames: (asset) => `media/${asset.names[0]}`,
}

The placeholders are [name], [hash], [ext], and [extname]. See Build Options for ChunkInfo/AssetInfo.

Minification

On by default. Turn it off to inspect the output:

ts
build: { minify: false }

Source maps

build.sourcemap covers JavaScript, TypeScript, and CSS:

ValueResult
falseNo maps (default).
trueExternal .map files + a sourceMappingURL comment.
"inline"Map embedded as a base64 data URL.
"hidden"External .map files, no comment.
ts
build: { sourcemap: true }

The base path

base is applied consistently across HTML, CSS url(), injected stylesheets, and JS-imported assets. Dynamic-import chunks stay relative, so they resolve correctly under any base.

ts
export default defineConfig({
  base: "/my-app/", // deploy under a sub-path
});
ts
export default defineConfig({
  base: "https://cdn.example.com/assets/", // or a CDN
});

Watch mode

vantris build --watch (or -w) rebuilds on every change, debounced. It does not start a dev server — it only rebuilds — and a failed build never stops the watcher.

bash
vantris build --watch

Use it when a separate process (an Electron shell, a backend serving dist/) consumes the build output and you want it kept fresh.

define — inlined constants

define replaces identifiers with a JSON literal everywhere they appear, in both dev and build. Dead branches guarded by an inlined false are tree-shaken away:

ts
export default defineConfig({
  define: { __DEV__: false, __APP_VERSION__: "1.0.0" },
});
ts
if (__DEV__) console.log("dev only"); // dropped in production
console.log(__APP_VERSION__);          // → console.log("1.0.0")

See Define / Global Constants.

Assets

Images, fonts, media, wasm, and txt resolve to hashed URLs when imported; json is imported as data. They behave identically in dev and build. See Static Assets.

Building a library instead

Set build.lib to bundle a single entry into esm + cjs + iife instead of an HTML app. The HTML pipeline is skipped. See Library Mode.

Then preview it

bash
vantris build && vantris preview

vantris preview serves the finished dist/ with no compilation — the closest local mirror of production. See Preview.

The internal cache

The build reuses Vantris's transparent cache in node_modules/.vantris/ for build metadata; it's wiped automatically when the Vantris version or your config changes. See Internal Cache.

Released under the MIT License.