Skip to content

ffss92/assets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

assets

Dead simple Vite + Go integration.

Usage

  1. 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"],
    },
  }
})
  1. 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",
}
  1. Before parsing templates, add a the Resolve method to the FuncMap.
tm := template.New("page").Funcs(template.FuncMap{
    "vite": vite.Resolve,
})
  1. Inside your templates, use the vite function to resolve assets.
{{vite "web/index.js" "web/index.css" }}
  1. Profit!

About

Example of Vite + Go integration

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages