An open API service indexing awesome lists of open source software.

https://github.com/indaco/tempo-demo

tempo demo project with components, asset sync, and live reload
https://github.com/indaco/tempo-demo

component-library demo go golang live-reload scaffolding templ tempo web-development

Last synced: 25 days ago
JSON representation

tempo demo project with components, asset sync, and live reload

Awesome Lists containing this project

README

          

# tempo-demo

This project demonstrates how [`tempo`](https://github.com/indaco/tempo) works in a real-world Go + [Templ](https://templ.guide) setup.

It covers:

- โœ… Default project structure
- โš™๏ธ A typical development workflow
- ๐ŸŽจ Component scaffolding with CSS and JS support
- ๐Ÿ’ก Live reloading and code generation

We'll walk through building a **Button** component with a variant (`outline`) and some JavaScript to showcase how `tempo` handles styles and scripts together.

## Prerequisites

Make sure you have the following tools installed:

```bash
go install github.com/a-h/templ/cmd/templ@latest
go install github.com/indaco/tempo/cmd/tempo@latest
go install github.com/air-verse/air@latest
```

## โšก Quickstart

If you just want to see the final result in action:

1. Make sure you have the [prerequisites](#prerequisites) installed:
2. Clone the repository:

```bash
git clone https://github.com/indaco/tempo-demo.git
cd tempo-demo

go mod download
```

3. Run the dev server:

```bash
make dev # or: task dev
```

4. Visit [http://localhost:7331](http://localhost:7331) in your browser.

The `button` component with live reload and asset sync is already set up โ€” no extra configuration needed.

Try editing any CSS or JS file in the `assets/` folder โ€” `tempo` will sync the changes, and `templ`โ€™s proxy will reload the browser for you.

### ๐Ÿ”จ Want to Learn How It Was Built?

The next section walks you through each step that was done to build this project from scratch using `tempo`, `templ`, and plain CSS/JS.

## ๐Ÿงช Getting Started

This section explains the full step-by-step process that was followed to build this project from scratch.

### 1. Create a new Go module

```bash
mkdir tempo-demo
cd tempo-demo

go mod init github.com/indaco/tempo-demo
go get github.com/a-h/templ@latest
```

### 2. Initialize tempo

```bash
tempo init
```

This creates a `tempo.yaml` config file. You can customize it by adding metadata like:

```yaml
templates:
user_data:
author: John Doe
year: 2025
```

### 3. Define your templates

```bash
tempo component define --js
```

This scaffolds template files under `.tempo-files/templates`.
Optionally update `.tempo-files/templates/component/templ/component.templ.gotxt` with metadata comments for reference.

### 4. Create your first component

```bash
tempo component new --name button --js
```

This will create:

- `assets/button` โ€“ CSS and JS files
- `components/button` โ€“ Templ code

Write styles and scripts in the assets folder to bring your component to life.

### 5. Sync asset files with templ components

```bash
tempo sync
```

This injects the contents of your CSS and JS into their corresponding `.templ` components.

### 6. Generate code with templ

```bash
templ fmt . && templ generate
```

Then clean up dependencies:

```bash
go mod tidy
```

### 7. Run the dev server

```bash
make dev # or: task dev
```

Then visit: [http://localhost:7331](http://localhost:7331)

This starts:

- `templ` in watch mode
- Asset syncing with live reload
- A hot-reloading Go server using air

### 8. Edit CSS or JS file

Just edit and save any CSS or JS file in assets/ โ€” `tempo` syncs your changes instantly, and `templ`โ€™s proxy takes care of reloading the browser automatically.

### 9. Build

Test your production-ready setup.

```bash
make build # or: task build
```

This will:

- Run `tempo sync --prod` (minifies and injects assets)
- Run `templ fmt` and `templ generate`
- Compile the Go binary into `tmp/bin/tempo-demo`

## ๐Ÿ› ๏ธ Running Tasks

This project supports both a `Makefile` and a `Taskfile.yaml`. You can use whichever you prefer:

### View available tasks

- _Makefile_:

```bash
make help
```

- _Taskfile_:

```bash
task --list-all
```

#### Common tasks

```bash
build: # Build for production with minified asset files
dev: # Run the dev server with live reload
```

## ๐Ÿ†“ License

This project is licensed under the MIT License โ€“ see the [LICENSE](./LICENSE) file for details.