Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

setup-frontend

FreeNo executable scriptsNot checked

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.

schuettcby schuettc★ 15 GitHub stars

About this skill

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

  • API Gateway is configured (from create-api)
  • Node.js 18+ installed

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

  • Convert each HTML page into a React component in src/pages/
  • Move CSS into component-level CSS or src/index.css
  • Move static assets (images, fonts) into public/
  • Replace direct DOM manipulation with React state and effects
  • Replace fetch() calls with the apiFetch helper
  • Add React Router if the app has multiple pages:
    cd frontend && npm install react-router-dom
    

Step 5: Create the CDK frontend stack

Create infrastructure/lib/frontend-stack.ts:

  • S3 Bucket:

    • Block ALL public access
    • Enable server-side encryption (AES-256)
    • RemovalPolicy.DESTROY for development
    • Auto-delete objects on stack deletion
  • Origin Access Control (OAC):

    • Create OAC — explain: "This is the secure link between CloudFront and your S3 bucket. It means only CloudFront can read your files — nobody can access S3 directly. This is a security best practice."
  • CloudFront Distribution:

    • Default behavior: S3 origin (Vite build output)
    • Additional behavior: /api/* -> API Gateway origin
    • HTTPS only (redirect HTTP -> HTTPS)
    • Default root object: index.html
    • SPA routing: Custom error responses — explain: "React handles page navigation in the browser (client-side routing). If someone bookmarks /dashboard and visits it directly, S3 doesn't have a file called /dashboard — it would return a 404. We tell CloudFront to serve index.html instead, and React figures out which page to show. This is standard for all React apps."
    • Price class: PriceClass.PRICE_CLASS_100 — explain: "This serves your content from data centers in North America and Europe. It's the cheapest option. If your users are in Asia or other regions, you can upgrade later."
    • Enable compression (gzip/brotli)
    • Response headers policy with security headers
  • S3 Deployment:

    • Use BucketDeployment to upload frontend/dist/
    • Cache control — explain: "Caching determines how long browsers and CloudFront remember your files before checking for updates:"
      • assets/* (hashed filenames): cached forever — "Vite adds a unique hash to each f
Full SKILL.md on GitHub

Install setup-frontend in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the setup-frontend skill do?

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 do I install the setup-frontend skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the setup-frontend skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare setup-frontend with