Gite is a fast, modern development server for Go web applications that provides Vite-like features including hot module replacement (HMR), asset bundling, and live reloading. Built with esbuild for lightning-fast asset processing and optimized for modern web development workflows.
- π₯ Hot Module Replacement (HMR) - Instant updates without page refresh
- π¦ Asset Bundling - Built-in esbuild integration for TypeScript/JavaScript
- π¨ CSS Preprocessing - Support for Tailwind CSS and SASS
- π Live Reloading - Automatic browser refresh on file changes
- π Fast Development - Optimized for developer experience
- π± Production Ready - Build and preview modes for deployment
- π§ Configurable - Environment variables and command-line flags
- ποΈ Compression - Built-in gzip compression for production
go get github.com/ahsanatha/gite
-
Development Mode (default):
go run main.go # or with dev flag go run main.go dev
Starts the development server with hot reloading at
http://localhost:5173
-
Build for Production:
go run main.go -build
Builds optimized assets for production
-
Preview Production Build:
go run main.go -preview
Serves the production build for testing
Create a new project with the following structure:
mkdir my-gite-app && cd my-gite-app
go mod init my-gite-app
go get github.com/ahsanatha/gite
your-project/
βββ web/ # Web root directory
β βββ index.html # Main HTML template
β βββ entry.ts # TypeScript entry point
β βββ styles/ # CSS/SASS files
βββ dist/ # Built assets (auto-generated)
βββ internal/ # Go packages (if using as library)
β βββ build/ # Build system
β βββ config/ # Configuration
β βββ server/ # HTTP server
βββ main.go # Application entry point
βββ gite.config.json # Optional configuration file
βββ package.json # Node.js dependencies (for CSS frameworks)
βββ tailwind.config.js # Tailwind CSS configuration
Create a minimal main.go
:
package main
import (
"embed"
"log"
"os"
"github.com/ahsanatha/gite/internal/config"
"github.com/ahsanatha/gite/internal/server"
)
//go:embed dist
var assets embed.FS
func main() {
cfg := config.LoadConfig()
srv := server.New(cfg, assets)
if err := srv.Start(); err != nil {
log.Printf("Server error: %v", err)
os.Exit(1)
}
}
Flag | Default | Description |
---|---|---|
-addr |
:5173 |
Server address |
-root |
web |
Web root directory |
-outdir |
dist |
Output directory for built assets |
-build |
false |
Build mode (build and exit) |
-preview |
false |
Preview mode (serve built assets) |
-tailwind |
false |
Enable Tailwind CSS |
-sass |
false |
Enable SASS preprocessing |
Variable | Default | Description |
---|---|---|
GITE_ADDR |
:5173 |
Server address |
GITE_ROOT |
web |
Web root directory |
GITE_OUTDIR |
dist |
Output directory |
GITE_API_PROXY |
http://localhost:8081 |
API proxy URL |
GITE_TAILWIND |
false |
Enable Tailwind CSS |
GITE_SASS |
false |
Enable SASS |
GITE_HMR |
true |
Enable hot module replacement |
GITE_GZIP |
true |
Enable gzip compression |
# Development with Tailwind CSS
GITE_TAILWIND=true go run main.go
# Custom port and API proxy
GITE_ADDR=:3000 GITE_API_PROXY=http://localhost:9000 go run main.go
# Build with SASS
GITE_SASS=true go run main.go -build
Gite uses Go's html/template
package. Your HTML files can access these template variables:
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
<!-- HMR client script (development only) -->
{{.HMRClient}}
</head>
<body>
<div id="app"></div>
<!-- In production, use manifest for asset URLs -->
{{if .Asset}}
<script src="{{.Asset "entry.js"}}"></script>
{{else}}
<script src="/static/entry.js"></script>
{{end}}
</body>
</html>
Gite automatically proxies /api/*
requests to your backend server:
// This will be proxied to http://localhost:8081/users
fetch('/api/users')
.then(response => response.json())
.then(data => console.log(data));
HMR is enabled by default in development mode. The HMR client automatically:
- Reloads the page when HTML templates change
- Hot-swaps JavaScript modules when possible
- Refreshes CSS without page reload
- Handles build errors gracefully
Enable Tailwind CSS processing:
# Command line
go run main.go -tailwind
# Environment variable
GITE_TAILWIND=true go run main.go
Create web/styles/input.css
:
@tailwind base;
@tailwind components;
@tailwind utilities;
/* Your custom styles */
.my-component {
@apply bg-blue-500 text-white p-4 rounded;
}
Enable SASS preprocessing:
# Command line
go run main.go -sass
# Environment variable
GITE_SASS=true go run main.go
Create web/styles/main.scss
:
$primary-color: #3b82f6;
$border-radius: 0.5rem;
.button {
background-color: $primary-color;
border-radius: $border-radius;
padding: 1rem 2rem;
&:hover {
background-color: darken($primary-color, 10%);
}
}
-
Build assets:
go run main.go -build
-
Test the build:
go run main.go -preview
-
Deploy:
go build -o myapp ./myapp -preview
Extend the build system by modifying internal/build/
packages:
// Add custom esbuild plugins
builder := build.NewBuilder(build.BuildConfig{
EntryPoints: []string{"web/entry.ts"},
OutDir: "dist",
Plugins: []api.Plugin{myCustomPlugin},
})
Add custom middleware in internal/server/handlers.go
:
func (s *Server) setupRoutes() {
// Add your custom middleware
http.Handle("/custom", s.customMiddleware(s.customHandler))
// Existing routes...
}
-
Port already in use:
GITE_ADDR=:3000 go run main.go
-
Assets not loading:
- Check that
web/entry.ts
exists - Verify the
web
directory structure - Run with
-build
flag to see build errors
- Check that
-
HMR not working:
- Ensure you're in development mode (not
-build
or-preview
) - Check browser console for WebSocket connection errors
- Verify firewall settings
- Ensure you're in development mode (not
-
Template errors:
- Check HTML template syntax
- Ensure template files are in the web root
- Look for template compilation errors in logs
Enable verbose logging:
GITE_DEBUG=true go run main.go
- Go: 1.24 or higher
- Node.js: 16+ (optional, for CSS frameworks like Tailwind)
- Modern Browser: For HMR WebSocket support
- β‘ Fast Builds: Powered by esbuild for sub-second build times
- π Instant HMR: WebSocket-based hot module replacement
- π¦ Efficient Bundling: Tree-shaking and code splitting
- ποΈ Optimized Output: Minification and compression for production
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
Gite is built with a modular architecture:
- Build System: esbuild integration with plugin support
- HMR Server: WebSocket-based hot module replacement
- Asset Manifest: Automatic asset versioning and mapping
- Plugin Manager: Extensible plugin system for custom processing
- Template Engine: Go html/template with asset injection
- Vue.js and React component support
- Advanced CSS optimization
- TypeScript type checking integration
- Docker containerization support
- Kubernetes deployment templates