Creating a New Project
The easiest way to start a new Cossack project is by using the create-cossack-app CLI tool.
Usage
Run the following command in your terminal:
npx create-cossack-app@latest my-cossack-appReplace my-cossack-app with your desired project name.
Adapter Selection
During the setup process, you will be prompted to choose a server adapter:
- Cloudflare Workers (Default): Best for edge deployments, automatic state persistence, and scalability. Requires a Cloudflare account.
- Node.js: Best for traditional server deployments (Docker, VPS) or local development without Cloudflare dependencies. Note that component state is memory-only in this mode.
The CLI will automatically configure your package.json, tsconfig.json, and entry points based on your selection.
Manual Installation
If you prefer to set up a project manually or integrate Cossack into an existing monorepo, follow these steps:
Install Core Dependencies:
pnpm add @cossackframework/core @cossackframework/renderer hono reflect-metadata
Install Adapter:
- For Cloudflare:
pnpm add -D wrangler @cloudflare/workers-types - For Node.js:
pnpm add @cossackframework/node-adapter ws @hono/node-serverandpnpm add -D @types/ws @types/node
- For Cloudflare:
Configure Vite: Cossack uses Vite for building both the client and server bundles. You will need separate configurations (
vite.client.config.tsandvite.ssr.config.ts) to handle the dual-build process.Create Entry Points:
src/client/entry-client.ts: Handles client-side hydration.src/index.ts: The server-side entry point (Worker or Node server).
Refer to the packages/create-cossack-app/template directory in the repository for a reference implementation.