A minimal starter template for WebGPU projects using TypeScript. Get up and running with modern GPU programming on the web in minutes.
- WebGPU ready β Pre-configured with
@webgpu/typesfor full TypeScript support - Modern tooling β Vite for fast development with HMR
- Strict TypeScript β Comprehensive type checking enabled
- Code quality β ESLint, Prettier, and Husky pre-configured
- Release workflow β Changesets for versioning and publishing
- Node.js v20 or higher (LTS recommended)
- pnpm v10.24.0 or higher
- A WebGPU-compatible browser:
- Chrome/Edge 113+ (Windows, macOS, Linux, Android)
- Firefox Nightly (with
dom.webgpu.enabledinabout:config) - Safari 18+ (macOS/iOS)
# Clone the repository
git clone https://github.com/ambilab/webgpu-template.git
cd webgpu-template
# Install dependencies
pnpm install
# Start development server
pnpm devOpen your browser at http://localhost:5173 to see a WebGPU-rendered triangle.
| Command | Description |
|---|---|
pnpm dev |
Start dev server with HMR |
pnpm build |
Type-check and build for production |
pnpm preview |
Preview the production build |
pnpm lint |
Run ESLint |
pnpm lint:fix |
Run ESLint with auto-fix |
pnpm format |
Format code with Prettier |
pnpm format:check |
Check formatting without changes |
pnpm typecheck |
Run TypeScript type checking |
pnpm clean |
Remove dist and cache directories |
pnpm changeset |
Create a changeset for version bump |
pnpm version:bump |
Bump version based on changesets |
pnpm release |
Build library and publish to npm |
webgpu-template/
βββ src/
β βββ main.ts # WebGPU demo entry point
βββ index.html # HTML template
βββ package.json
βββ tsconfig.json # TypeScript configuration
βββ vite.config.ts # Vite configuration
βββ eslint.config.js # ESLint flat config
βββ prettier.config.js # Prettier configuration
βββ commitlint.config.js # Commit message linting
The template includes a minimal WebGPU demo that:
- Checks WebGPU support β Displays a helpful error if unavailable
- Initializes the GPU β Requests adapter and device
- Configures the canvas β Sets up the WebGPU context
- Creates shaders β Vertex and fragment shaders in WGSL
- Builds a pipeline β Configures the render pipeline
- Renders a triangle β Clears to dark gray, draws a blue triangle
// Example: Creating a shader module
const vertexShaderModule = device.createShaderModule({
label: 'Vertex Shader',
code: `
@vertex
fn main(@builtin(vertex_index) vertexIndex: u32) -> @builtin(position) vec4f {
var positions = array<vec2f, 3>(
vec2f(0.0, 0.5),
vec2f(-0.5, -0.5),
vec2f(0.5, -0.5)
);
return vec4f(positions[vertexIndex], 0.0, 1.0);
}
`,
});| Browser | Version | Status |
|---|---|---|
| Chrome/Edge | 113+ | Enabled by default |
| Firefox | Nightly | Enable dom.webgpu.enabled |
| Safari | 18+ | Enabled by default |
The demo displays a user-friendly error message if WebGPU is not supported.
- WebGPU β Modern GPU API for the web
- TypeScript β Type-safe JavaScript
- Vite β Fast build tool with HMR
- WGSL β WebGPU Shading Language
ISC