Skip to main content
The vitejs package (from gocopper/pkg) connects your Go templates to Vite: the dev server during development, and hashed production assets in a release build. Your templates do not change between the two.

viteAssets

The layout calls a single template function in its <head>:
web/src/layouts/main.html
viteAssets emits whatever the current mode needs, so you never write script tags by hand.

Development Mode

With dev_mode enabled, viteAssets points the page at the Vite dev server:
config/dev.toml
It injects the Vite client and your entrypoint as module scripts, along with the React fast-refresh preamble, so HMR works without any frontend configuration. Copper discovers your entrypoint by convention: src/main.js, .ts, .jsx, or .tsx.

Production Mode

When dev_mode is off (the default), viteAssets reads the Vite build manifest from the assets embedded in your binary and emits the hashed <script> and <link rel="stylesheet"> tags for your entrypoint. There is nothing to configure: the frontend build (npm run build) emits the manifest into web/build/static, and copper build embeds it.

Wiring

The scaffolded project wires this up for you: vitejs.WireModule provides *vitejs.Assets, and web/wire.go registers its render func:
web/wire.go

Configuration

The dev-mode integration currently targets React, since the HMR preamble it injects is React’s fast refresh. Production mode is framework-agnostic.