Index of every page on this site: llms.txt
TypeScript
Build Plugins Since 3.0.0

Build Plugins

The Vue, React, Svelte, and Solid.js packages each ship a Vite plugin at @unhead/{framework}/vite. Solid.js uses the package name @unhead/solid-js.

For SSR handoff of tags from another Vite plugin, see Vite Plugin Tags.

Setup

Install your framework's Unhead package, then add the plugin to your Vite config:

The build plugin needs a parser. Vite 8 includes Rolldown, so Unhead reuses rolldown/utils. With Vite 6 or 7, webpack, Rspack, or Rollup, install the Oxc fallback:

pnpm add -D oxc-parser

Projects that use Unhead only at runtime do not need to install a parser.

vite.config.ts
import vue from '@vitejs/plugin-vue'
import { Unhead } from '@unhead/vue/vite'

export default defineConfig({
  plugins: [vue(), Unhead()],
})

Included transforms

The plugin combines several build-time optimizations:

  • Tree-shaking: Removes deprecated server composables and useSchemaOrg calls from client bundles
  • useSeoMeta transform: Converts useSeoMeta() calls into raw useHead() calls at build time
  • Server-only crawler tags: Removes eligible crawler tag inputs from client bundles when you enable it for server-rendered or prerendered pages
  • Inline script transform: Transpiles static inline scripts to Vite's configured browser target
  • Minify transform: Optionally pre-minifies static inline script/style content in the same AST pass
  • Dev validation: Auto-injects ValidatePlugin in dev so head tag warnings surface in the browser console (enabled by default)
  • DevTools: Registers Unhead's Vite DevTools integration by default; the panel activates when Vite DevTools is enabled

Options

Unhead({
  // Disable server composable tree-shaking
  treeshake: false,
  // Disable useSeoMeta → useHead transform
  transformSeoMeta: false,
  // Remove eligible crawler tag inputs in an SSR or prerendered app
  serverOnlyCrawlerTags: true,
  // Disable automatic inline script transpilation
  transformInlineScripts: false,
  // Pre-minify inline script/style content
  minify: { js: createJSMinifier(), css: createCSSMinifier() },
  // File filter (shared across all transforms)
  filter: { exclude: [/some-file/] },
})
OptionTypeDefaultDescription
treeshakeobject | falseenabledTree-shake server composables from client bundles
transformSeoMetaobject | falseenabledTransform useSeoMeta() to useHead()
serverOnlyCrawlerTagsobject | booleandisabledStrip eligible crawler tag inputs from client builds
transformInlineScriptsobject | falseenabledTranspile static inline scripts to Vite's resolved build.target
minifyobject | falsedisabledPre-minify static inline script/style
validatebooleanenabledAuto-inject ValidatePlugin in dev for head tag warnings
devtoolsobject | falseincludedVite DevTools integration (dev only)
filterobjectUnsetShared include/exclude file filter
sourcemapbooleanUnsetEnable sourcemap generation for transforms

Set serverOnlyCrawlerTags to true for build-time stripping without extra client code. Set serverOnlyCrawlerTags: { runtime: true } to also block crawler tags from dynamic client entries. The options object also accepts a build filter and extra import paths.

Inline scripts inherit Vite's resolved build.target. Override it without changing the target for the rest of the bundle:

Unhead({
  transformInlineScripts: { target: 'chrome77' },
})

Other Bundlers

The Vue, React, Svelte, and Solid.js packages expose a unified /bundler entry with per-bundler methods:

import { Unhead } from '@unhead/vue/bundler'

export default {
  plugins: Unhead().webpack(),
}

The bundler entry also exposes .rspack() and .rollup(). Validation and DevTools injection are Vite-only. Rollup cannot infer whether it is building for the client or server, so target-dependent transforms remain conservative; use .vite() or .webpack() when you need target-aware optimization.

Inline script target inheritance is Vite-only. Rollup has no browser target contract. Unplugin provides the webpack and Rspack targets, but not their transpilers, so Unhead cannot apply those targets to an inline string. Existing explicit minifier configuration is unchanged.

Did this page help you?