mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-21 02:59:36 -06:00
feat(template): add vercel template
This commit is contained in:
parent
abbe86dcce
commit
61a6af5300
37
templates/.gitignore
vendored
Normal file
37
templates/.gitignore
vendored
Normal 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
6
templates/cloudflare/type.d.ts
vendored
Normal 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
7
templates/vercel/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
.zig-cache/
|
||||
zig-out/
|
||||
!zig-out/pkg/**/*.d.ts
|
||||
node_modules/
|
||||
|
||||
# Vercel
|
||||
.vercel
|
||||
16
templates/vercel/.vercelignore
Normal file
16
templates/vercel/.vercelignore
Normal file
@ -0,0 +1,16 @@
|
||||
# Zig
|
||||
.zig-cache
|
||||
zig-out
|
||||
|
||||
# ZX
|
||||
/dist
|
||||
/bundle
|
||||
|
||||
# Node.js
|
||||
node_modules
|
||||
|
||||
# Cloudflare
|
||||
.wrangler/
|
||||
|
||||
app/assets/playground/
|
||||
.vercel
|
||||
84
templates/vercel/README.md
Normal file
84
templates/vercel/README.md
Normal 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)**
|
||||
|
||||
[](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/)
|
||||
7
templates/vercel/api/index.ts
Normal file
7
templates/vercel/api/index.ts
Normal 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 }));
|
||||
32
templates/vercel/build.zig
Normal file
32
templates/vercel/build.zig
Normal 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\"",
|
||||
},
|
||||
});
|
||||
}
|
||||
14
templates/vercel/package.json
Normal file
14
templates/vercel/package.json
Normal 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
6
templates/vercel/type.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
declare module "*.wasm?module" {
|
||||
/** Compiled Ziex WASI Binary */
|
||||
const module: WebAssembly.Module;
|
||||
export default module;
|
||||
}
|
||||
|
||||
12
templates/vercel/vercel.json
Normal file
12
templates/vercel/vercel.json
Normal 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"
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user