feat(template): add vercel template

This commit is contained in:
Nurul Huda (Apon) 2026-03-20 05:04:39 +06:00
parent abbe86dcce
commit 61a6af5300
No known key found for this signature in database
GPG Key ID: 5D3F1DE2855A2F79
10 changed files with 221 additions and 0 deletions

37
templates/.gitignore vendored Normal file
View File

@ -0,0 +1,37 @@
# General ignores
.zig-cache/
zig-out/
dist/
bundle/
node_modules/
.wrangler/
# Ignore all files by default
**/*
# unignore directories so we can unignore files within them
!*/
!*/**/
# base template (keep everything except ignored above)
!_base/**/*
!.gitignore
# cloudflare template (keep only specific overrides)
!cloudflare/.gitignore
!cloudflare/package.json
!cloudflare/wrangler.jsonc
!cloudflare/build.zig
!cloudflare/app/main.ts
!cloudflare/type.d.ts
!cloudflare/README.md
# vercel template
!vercel/.gitignore
!vercel/.vercelignore
!vercel/package.json
!vercel/build.zig
!vercel/api/index.ts
!vercel/vercel.json
!vercel/README.md
!vercel/type.d.ts

6
templates/cloudflare/type.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
declare module "*.wasm" {
/** Compiled Ziex WASI Binary */
const module: WebAssembly.Module;
export default module;
}

7
templates/vercel/.gitignore vendored Normal file
View File

@ -0,0 +1,7 @@
.zig-cache/
zig-out/
!zig-out/pkg/**/*.d.ts
node_modules/
# Vercel
.vercel

View File

@ -0,0 +1,16 @@
# Zig
.zig-cache
zig-out
# ZX
/dist
/bundle
# Node.js
node_modules
# Cloudflare
.wrangler/
app/assets/playground/
.vercel

View File

@ -0,0 +1,84 @@
# Ziex App — Vercel
> A starter template for building web applications with [Ziex](https://ziex.dev) deployed on [Vercel](https://vercel.com/).
**[Documentation →](https://ziex.dev)**
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/ziex-dev/template-vercel)
## Getting Started
### Prerequisites
**1. Install ZX CLI**
```bash
# Linux/macOS
curl -fsSL https://ziex.dev/install | bash
# Windows
powershell -c "irm ziex.dev/install.ps1 | iex"
```
**2. Install Zig**
```bash
brew install zig # macOS
winget install -e --id zig.zig # Windows
```
[_Other platforms →_](https://ziglang.org/learn/getting-started/)
**3. Install Node.js** (for Vercel CLI)
[_Download →_](https://nodejs.org/)
## Project Structure
```
├── api/
│ └── index.ts # Vercel Edge Function entrypoint
├── app/
│ ├── assets/ # Static assets (CSS, images, etc)
│ ├── main.zig # Zig entrypoint
│ ├── pages/ # Pages (Zig/ZX)
│ │ ├── layout.zx # Root layout
│ │ ├── page.zx # Home page
│ │ ├── client.zx # Client-side component
│ │ └── ...
│ └── public/ # Public static files (favicon, etc)
├── build.zig # Zig build script
├── build.zig.zon # Zig package manager config
└── package.json
```
## Usage
### Development
```bash
vercel dev
```
App will be available at [`http://localhost:3000`](http://localhost:3000) with hot reload enabled.
> **Note:** Run `vercel dev` at least once before opening the project in your editor — it triggers the build and generates type definitions under `zig-out/pkg/`.
### Deploy to Vercel
```bash
vercel deploy
```
Or click the **Deploy with Vercel** button above for one-click deployment.
## Contributing
Contributions are welcome! For feature requests, bug reports, or questions, see the [Ziex Repo](https://github.com/ziex-dev/ziex).
## Links
- [Documentation](https://ziex.dev)
- [Discord](https://ziex.dev/r/discord)
- [Vercel Docs](https://vercel.com/docs)
- [Zig Language](https://ziglang.org/)

View File

@ -0,0 +1,7 @@
import module from "../zig-out/bin/zx_app.wasm?module";
import { Ziex } from "../zig-out/pkg/ziex/index.js";
import { handle } from "../zig-out/pkg/ziex/vercel/index.js";
export const config = { runtime: "edge" };
export default handle(new Ziex({ module }));

View File

@ -0,0 +1,32 @@
const std = @import("std");
const zx = @import("zx");
pub fn build(b: *std.Build) !void {
// --- Target and Optimize from `zig build` arguments ---
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
// --- ZX App Executable ---
const app_exe = b.addExecutable(.{
.name = "zx_app",
.root_module = b.createModule(.{
.root_source_file = b.path("app/main.zig"),
.target = target,
.optimize = optimize,
}),
});
// --- ZX setup: wires dependencies and adds `zx`/`dev` build steps ---
var zx_build = try zx.init(b, app_exe, .{});
// HACK: on wasi we do not inject jsglue automatically yet
if (target.result.os.tag == .wasi)
zx_build.addElement(.{
.parent = .body,
.position = .ending,
.element = .{
.tag = "script",
.attributes = "src=\"https://cdn.jsdelivr.net/npm/ziex@0.1.0-dev.804/wasm/init.min.js\"",
},
});
}

View File

@ -0,0 +1,14 @@
{
"name": "ziex_cloudflare",
"type": "module",
"scripts": {
"build": "vercel build",
"deploy": "vercel deploy --prebuilt"
},
"dependencies": {
"ziex": "^0.1.0-dev.804"
},
"devDependencies": {
"vercel": "^50.34.1"
}
}

6
templates/vercel/type.d.ts vendored Normal file
View File

@ -0,0 +1,6 @@
declare module "*.wasm?module" {
/** Compiled Ziex WASI Binary */
const module: WebAssembly.Module;
export default module;
}

View File

@ -0,0 +1,12 @@
{
"$schema": "https://openapi.vercel.sh/vercel.json",
"framework": null,
"buildCommand": "zig build -Dtarget=wasm32-wasi -Doptimize=ReleaseSmall && mkdir -p zig-out/pkg/ziex && cp -r node_modules/ziex/ zig-out/pkg/ziex/",
"outputDirectory": "zig-out/static",
"rewrites": [
{
"source": "/(.*)",
"destination": "/api/index"
}
]
}