Setup frontend

From schuettc/claude-code-plugins · View interactive version

Setup frontend is an AI agent skill from the GitHub repository schuettc/claude-code-plugins. Sets up a Vite + React frontend with S3 and CloudFront hosting. Use when setting up frontend hosting, CDN, static file serving, or creating the React app.

How to use this skill

Skill file

Setup Frontend — Vite + React on S3 + CloudFront

You are creating a Vite + React frontend and setting up S3 + CloudFront hosting. This replaces Express's express.static() with a build pipeline and CDN hosting.

Prerequisites

What To Do

Phase 1: Plan

Present the plan to the user, explaining each concept:

  1. "We'll create a React app using Vite (a fast build tool). React lets you build your UI with reusable components. Vite compiles everything into optimized static files — HTML, CSS, and JavaScript — that any browser can load."
  2. "Everything goes through one CloudFront URL — your website files AND your API. When someone visits your site, CloudFront serves the React app from S3. When the app calls /api/..., CloudFront routes that to API Gateway. This means no cross-origin issues."
  3. "I'll convert your existing HTML pages into React components. The styling stays the same — we're reorganizing, not redesigning."
  4. Ask about custom domain: "Your site will get a CloudFront URL like d1234abcd.cloudfront.net. If you want a custom domain like myapp.com, we'd need to set up Route53 (AWS's DNS service, ~$0.50/month per domain) and an SSL certificate (free). Want to set that up now, or use the default URL? You can always add a custom domain later."

Phase 2: Execute

Step 1: Create the Vite + React project
npm create vite@latest frontend -- --template react-ts
cd frontend && npm install

Project structure:

frontend/
├── index.html
├── public/
│   └── favicon.ico
├── src/
│   ├── main.tsx
│   ├── App.tsx
│   ├── components/
│   ├── pages/
│   ├── hooks/
│   │   └── useApi.ts
│   ├── lib/
│   │   └── api.ts
│   ├── App.css
│   └── index.css
├── vite.config.ts
├── tsconfig.json
└── package.json
Step 2: Configure Vite

Update frontend/vite.config.ts:

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  server: {
    proxy: {
      '/api': 'http://localhost:3000', // Proxy API calls to Express during development
    },
  },
  build: {
    outDir: 'dist',
    sourcemap: true,
  },
});
Step 3: Set up API client

Create frontend/src/lib/api.ts:

const API_BASE = import.meta.env.VITE_API_URL || '';

export async function apiFetch(path: string, options?: RequestInit) {
  const response = await fetch(`${API_BASE}${path}`, {
    ...options,
    headers: {
      'Content-Type': 'application/json',
      ...options?.headers,
    },
  });
  if (!response.ok) {
    throw new Error(`API error: ${response.status}`);
  }
  return response.json();
}

Note: VITE_API_URL is empty in production (same-origin). Vite injects VITE_-prefixed env vars at build time.

Step 4: Migrate existing HTML/CSS into React components

```bash

cd frontend && npm install react-router-dom

```

Step 5: Create the CDK frontend stack

Create infrastructure/lib/frontend-stack.ts:

Step 6: Add build step

Update the CDK stack or add a build step that:

  1. Runs cd frontend && npm run build before deploying
  2. Sets VITE_API_URL if needed (empty string for same-origin)
  3. Uploads frontend/dist/ to S3
Step 7: Verify local development
cd frontend && npm run dev

Phase 3: Verify

  1. Run cd frontend && npm run build to verify the Vite build succeeds
  2. Run cd infrastructure && npx cdk synth to verify CDK compilation
  3. Update .migration/plan.md to mark setup-frontend as complete

Important Notes

Security

Vite Specifics

Development Workflow

Cost

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.