Dead simple Vite + Go integration.
- Install and configure Vite.
Your vite.config.js
should look like this:
import { defineConfig } from "vite"
export default defineConfig({
build: {
manifest: true,
outDir: "web/dist",
rollupOptions: {
input: ["web/index.js", "web/index.css"],
},
}
})
- Create a
Vite
struct.
For production, the config should look like this:
vite := assets.Vite{
ManifestPath: "web/dist/.vite/manifest.json",
Mode: assets.ModeProduction,
StaticURL: "/static",
}
For development, the config should look like this:
vite := assets.Vite{
Mode: assets.ModeDevelopment,
DevServerURL: "http://localhost:5173",
}
- Before parsing templates, add a the
Resolve
method to theFuncMap
.
tm := template.New("page").Funcs(template.FuncMap{
"vite": vite.Resolve,
})
- Inside your templates, use the
vite
function to resolve assets.
{{vite "web/index.js" "web/index.css" }}
- Profit!