### Build and Start Waku Example Source: https://github.com/wakujs/waku/blob/main/CONTRIBUTING.md Builds and then starts a specific Waku example. Use this to see the example in a production-like state. ```shell pnpm -F 01_template build pnpm -F 01_template start ``` -------------------------------- ### Install Dependencies and Run Development Server Source: https://github.com/wakujs/waku/blob/main/docs/guides/getting-started.mdx After creating the project, navigate into the project directory, install the necessary dependencies, and start the development server to view your app. ```bash cd waku-project npm install npm run dev ``` -------------------------------- ### Run Waku Example in Development Mode Source: https://github.com/wakujs/waku/blob/main/CONTRIBUTING.md Starts a specific Waku example (e.g., 01_template) in development mode. This is useful for iterative development and testing of examples. ```shell pnpm -F 01_template dev ``` -------------------------------- ### Jotai Provider Setup Source: https://github.com/wakujs/waku/blob/main/packages/website/private/contents/post-002.mdx Set up Jotai's `Provider` component to manage global state. This example creates a store and wraps the application's children with the provider. ```tsx 'use client'; import { createStore, Provider } from 'jotai'; const store = createStore(); export const Providers = ({ children }) => { return {children}; }; ``` -------------------------------- ### Install Minimal Client Runtime with `Root` Source: https://github.com/wakujs/waku/blob/main/docs/guides/minimal-api.mdx The `Root` component is used to install the minimal client runtime for Waku. ```typescript import { Root } from "waku/minimal/client"; function App() { return ( {/* Client-side content */} ); } ``` -------------------------------- ### Route Grouping Example Directory Structure Source: https://github.com/wakujs/waku/blob/main/packages/website/private/contents/post-010.mdx Illustrates how to structure directories using parentheses to create route groups for shared layouts. ```bash ├── (some-group) │ ├── _layout.tsx │ ├── about.tsx │ └── other-page.tsx └── index.tsx ``` -------------------------------- ### Global Stylesheet Example Source: https://github.com/wakujs/waku/blob/main/README.md A basic example of a global stylesheet, demonstrating the use of CSS imports. This file can contain any valid CSS, including framework-specific directives. ```css /* ./src/styles.css */ @import 'tailwindcss'; ``` -------------------------------- ### Install Serverless Framework Plugin Source: https://github.com/wakujs/waku/blob/main/docs/guides/aws-lambda.mdx Add the `serverless-scriptable-plugin` to your project's development dependencies using pnpm. ```sh pnpm add -D serverless-scriptable-plugin ``` -------------------------------- ### Install Dependencies with PNPM Source: https://github.com/wakujs/waku/blob/main/CONTRIBUTING.md Installs project dependencies using PNPM. Ensure Corepack is enabled first. ```shell corepack enable pnpm install ``` -------------------------------- ### Compile Waku Project Source: https://github.com/wakujs/waku/blob/main/CONTRIBUTING.md Builds the Waku project. This command must be run before attempting to run examples. ```shell pnpm run compile ``` -------------------------------- ### Install Dependencies for React Compiler Source: https://github.com/wakujs/waku/blob/main/docs/guides/react-compiler.mdx Use this command to install the necessary Vite React plugin, React Compiler Babel plugin, and Rolldown Babel plugin when upgrading an existing Waku project. ```bash npm install -D @vitejs/plugin-react babel-plugin-react-compiler @rolldown/plugin-babel ``` -------------------------------- ### Platform Environment Bindings Example Source: https://github.com/wakujs/waku/blob/main/docs/guides/adapter-authoring.mdx Demonstrates how to use `setAllEnv` to integrate platform-specific environment bindings into Waku's request processing. ```typescript export default createServerEntryAdapter( ({ processRequest, processBuild, setAllEnv }) => { return { fetch: async (req: Request, env: Record) => { setAllEnv(env); const res = await processRequest(req); return res || new Response('Not Found', { status: 404 }); }, build: processBuild, }; }, ); ``` -------------------------------- ### Async Server Component Example Source: https://github.com/wakujs/waku/blob/main/docs/guides/getting-started.mdx This is an example of an async server component. It allows for data fetching directly on the server, which can improve client bundle size and enable server-side logic. ```tsx export default async function HomePage() { const data = await getData(); // ...rest of the file } ``` -------------------------------- ### Netlify Adapter for Pure SSG Source: https://github.com/wakujs/waku/blob/main/README.md Configure the Netlify adapter for Waku to deploy a purely static site. This setup avoids deploying serverless functions. ```ts import { fsRouter } from 'waku'; import adapter from 'waku/adapters/netlify'; export default adapter(fsRouter(import.meta.glob('./pages/**/*.{tsx,ts}')), { static: true, }); ``` -------------------------------- ### Create Waku Project with Cloudflare Template Source: https://github.com/wakujs/waku/blob/main/packages/website/private/contents/post-0016.mdx Use this command to initialize a new Waku project pre-configured for Cloudflare Workers. It installs `@hiogawa/node-loader-cloudflare` automatically. ```sh npm create waku@latest -- --template 07_cloudflare ``` -------------------------------- ### Create Home Page with Dynamic Rendering Source: https://github.com/wakujs/waku/blob/main/packages/website/private/contents/post-003.mdx Example of a home page component that fetches data and is configured for dynamic rendering at request time. ```tsx // ./src/pages/index.tsx // Create home page export default async function HomePage() { const data = await getData(); return ( <>

{data.title}

{data.content}
); } const getData = async () => { /* ... */ }; export const getConfig = async () => { return { render: 'dynamic', }; }; ``` -------------------------------- ### Install Cloudflare Vite Plugin and Wrangler Source: https://github.com/wakujs/waku/blob/main/docs/guides/cloudflare.mdx Install the necessary development dependencies for integrating Waku with Cloudflare Workers. ```sh npm install --save-dev @cloudflare/vite-plugin wrangler ``` -------------------------------- ### Static API Example Source: https://github.com/wakujs/waku/blob/main/docs/create-pages.mdx Defines a static API endpoint for RSS feed generation. ```APIDOC ## GET /rss.xml ### Description Provides a static RSS feed. ### Method GET ### Endpoint /rss.xml ### Request Example (No request body for GET) ### Response #### Success Response (200) - **Content-Type**: application/rss+xml - **Body**: RSS XML content ### Response Example ```xml ``` ``` -------------------------------- ### Build and Run Docker Container Source: https://github.com/wakujs/waku/blob/main/docs/guides/docker.mdx Command to build the Docker image and start the Waku application container using Docker Compose. ```sh docker compose up --build ``` -------------------------------- ### Static Slice Creation Source: https://github.com/wakujs/waku/blob/main/docs/create-pages.mdx Example of creating a reusable static slice component. ```APIDOC ## createSlice({ render: 'static', id: 'one', component: SliceOne }) ### Description Creates a static slice with the ID 'one' using the `SliceOne` component. ### Parameters - **render**: 'static' - **id**: 'one' - **component**: `SliceOne` (imported component) ``` -------------------------------- ### Path Specification Examples Source: https://github.com/wakujs/waku/blob/main/docs/guides/custom-router.mdx Illustrates different path specifications for Waku routes, including literal segments, groups for dynamic slugs, and wildcards for catch-all paths. ```ts // / []; ``` ```ts // /about [{ type: 'literal', name: 'about' }]; ``` ```ts // /posts/[slug] [ { type: 'literal', name: 'posts' }, { type: 'group', name: 'slug' }, ]; ``` ```ts // /files/[...path] [ { type: 'literal', name: 'files' }, { type: 'wildcard', name: 'path' }, ]; ``` -------------------------------- ### Dockerfile for Waku App Source: https://github.com/wakujs/waku/blob/main/docs/guides/docker.mdx This Dockerfile uses a multi-stage build to create a production-ready Docker image for a Waku application. The builder stage installs dependencies and builds the app, while the runner stage installs only production dependencies and copies the build output. ```dockerfile FROM node:22-alpine AS builder WORKDIR /app COPY package*.json ./ RUN npm ci COPY . . RUN npm run build FROM node:22-alpine AS runner WORKDIR /app ENV NODE_ENV=production COPY package*.json ./ RUN npm ci --omit=dev COPY --from=builder /app/dist ./dist EXPOSE 8080 CMD ["npm", "run", "start"] ``` -------------------------------- ### Fetch Blog Article Data in Waku Source: https://github.com/wakujs/waku/blob/main/README.md Fetch and render blog articles using server components. This example demonstrates fetching article content and metadata, and configuring static path generation. ```tsx // ./src/pages/blog/[slug].tsx import type { PageProps } from 'waku/router'; import { MDX } from '../../components/mdx'; import { getArticle, getStaticPaths } from '../../lib/blog'; export default async function BlogArticlePage({ slug, }: PageProps<'/blog/[slug]'>) { const article = await getArticle(slug); return ( <> {article.frontmatter.title}

{article.frontmatter.title}

{article.content} ); } export const getConfig = async () => { const staticPaths = await getStaticPaths(); return { render: 'static', staticPaths, } as const; }; ``` -------------------------------- ### Docker Compose Up Command Source: https://context7.com/wakujs/waku/llms.txt Command to build and start the Waku application defined in docker-compose.yml. The application will be accessible at http://localhost:8080. ```sh docker compose up --build # App available at http://localhost:8080 ``` -------------------------------- ### Static API with Dynamic Segment Example Source: https://github.com/wakujs/waku/blob/main/docs/create-pages.mdx Defines a static API with a dynamic segment that can be pre-rendered for specific paths. ```APIDOC ## GET /feeds/[category] ### Description Provides static feeds for different categories. ### Method GET ### Endpoint /feeds/:category ### Parameters #### Path Parameters - **category** (string) - Required - The category of the feed. ### Request Example (No request body for GET) ### Response #### Success Response (200) - **Body**: Text indicating the feed for the specified category. ### Response Example ``` Feed for news ``` ``` -------------------------------- ### Vercel Adapter for Pure SSG Source: https://github.com/wakujs/waku/blob/main/README.md Configure the Vercel adapter for Waku to deploy a purely static site. This setup avoids deploying serverless functions. ```ts import { fsRouter } from 'waku'; import adapter from 'waku/adapters/vercel'; export default adapter(fsRouter(import.meta.glob('./pages/**/*.{tsx,ts}')), { static: true, }); ``` -------------------------------- ### Dynamic Slice Creation Source: https://github.com/wakujs/waku/blob/main/docs/create-pages.mdx Example of creating a reusable dynamic slice component. ```APIDOC ## createSlice({ render: 'dynamic', id: 'two', component: SliceTwo }) ### Description Creates a dynamic slice with the ID 'two' using the `SliceTwo` component. ### Parameters - **render**: 'dynamic' - **id**: 'two' - **component**: `SliceTwo` (imported component) ``` -------------------------------- ### Dynamic API Example Source: https://github.com/wakujs/waku/blob/main/docs/create-pages.mdx Defines a dynamic API endpoint that accepts a user ID parameter. ```APIDOC ## API /api/users/[id] ### Description Handles dynamic API requests for user data based on ID. ### Method GET ### Endpoint /api/users/:id ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the user. ### Request Example (No request body for GET) ### Response #### Success Response (200) - **id** (string) - The ID of the user. ### Response Example ```json { "id": "123" } ``` ``` -------------------------------- ### Configure Waku Project with defineConfig Source: https://context7.com/wakujs/waku/llms.txt Customize Waku project settings like base path, source/output directories, and Vite configurations using defineConfig. This example includes Tailwind CSS and React plugins. ```typescript import babel from '@rolldown/plugin-babel'; import tailwindcss from '@tailwindcss/vite'; import react, { reactCompilerPreset } from '@vitejs/plugin-react'; import { defineConfig } from 'waku/config'; export default defineConfig({ // Base path for all HTTP routes (default: '/') basePath: '/', // Source directory (default: 'src') srcDir: 'src', // Build output directory (default: 'dist') distDir: 'dist', // Private server-only files directory (default: 'private') privateDir: 'private', // RSC request base path (default: 'RSC') rscBase: 'RSC', // Override adapter (e.g. for Cloudflare without env vars) // unstable_adapter: 'waku/adapters/cloudflare', // Vite configuration — plugins, aliases, resolve options, etc. vite: { plugins: [ tailwindcss(), react(), babel({ presets: [reactCompilerPreset()] }), ], resolve: { // Prevent duplicate React in monorepos dedupe: ['react', 'react-dom'], }, }, }); ``` -------------------------------- ### Root Layout with Header and Footer Source: https://github.com/wakujs/waku/blob/main/README.md An example of a root layout that includes global components like Header and Footer, alongside children content. It is configured for static rendering. ```tsx // ./src/pages/_layout.tsx import '../styles.css'; import { Providers } from '../components/providers'; import { Header } from '../components/header'; import { Footer } from '../components/footer'; // Create root layout export default async function RootLayout({ children }) { return (
{children}