Skip to content

zenbal/vite-plugin-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vite-plugin-go

Vite Backend Integration in a single file for Go web applications.

Installation

Use the following command:

go get github.com/zenbal/vite-plugin-go

or just copy the contents of plugin.go into your project.

Usage

Make sure that vite generates a manifest.json

package main

import (
    "os"
    "github.com/zenbal/vite-plugin-go"
)

func main() {
    plugin, _ := viteplugin.New(viteplugin.PluginConfig{
        FileSystem:   os.DirFS("./dist"),
        ManifestPath: ".vite/manifest.json", // relative to FileSystem
        Prefix:       "/static/",            // optionally add a prefix for file URLs (has no effect in development mode)
        DevMode:      false,
        DevURL:       "http://localhost:5173",
        DevEntry:     "main.ts",
    })
    // iterate over entrypoints
    for _, chunk := range plugin.EntryPoints {
        html, err := plugin.RawHTML(chunk)
        fmt.Println(html)
    }
    // or access specific ones
    html, err := plugin.RawHTML(plugin.EntryPoints["main.ts"])
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages