• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
stevekrouse

stevekrouse

site-diogenesoftoronto

Remix of diogenesoftoronto/site
Public
Like
site-diogenesoftoronto
Home
Code
9
skills
1
.gitignore
.vtignore
AGENTS.md
App.tsx
CRUSH.md
deno.json
index.html
H
index.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
skills
/
val-town-development.md
Code
/
skills
/
val-town-development.md
Search
…
val-town-development.md

Val Town Development Skills & Learnings

Overview

Val Town is a serverless platform for running JavaScript/TypeScript code with a unique deployment model focused on "vals" (individual code modules). This document captures key learnings from converting a static site to a React TSX application deployed on Val Town.

Core Concepts Learned

1. Val Town Architecture

  • Vals: Individual code modules that can be HTTP endpoints, cron jobs, or email handlers
  • File-based deployment: Code is deployed by pushing files via the vt CLI tool
  • Branch-based versioning: Each val can have multiple branches (main, dev, etc.)
  • No traditional server management: Platform handles scaling, hosting, and infrastructure

2. Deployment Workflow

# Check status of local changes vt status # Push changes to deploy vt push # Open deployed val in browser vt browse # Clone existing vals vt clone <valUri> [targetDir] # Create new vals vt create <valName> [targetDir]

3. React Integration in Val Town

JSX Configuration

/** @jsxImportSource https://esm.sh/react@18.2.0 */ import React, { useState } from "https://esm.sh/react@18.2.0"; import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
  • Pinned versions: Always pin React versions to avoid breaking changes
  • ESM.sh imports: Use https://esm.sh for all external dependencies
  • No build step: Direct browser execution of TSX files

Component Structure

  • Functional components with hooks
  • TypeScript interfaces for props and state
  • TailwindCSS for styling (CDN-based)
  • Client-side rendering with createRoot

4. Progressive Enhancement Pattern

No-JS Fallback Strategy

<noscript> <!-- Graceful degradation for users without JavaScript --> <div>Content requiring JavaScript...</div> </noscript> <div id="root"></div> <script type="module" src="index.tsx"></script>

Benefits:

  • SEO friendly: Search engines can index the fallback content
  • Accessibility: Users with disabled JavaScript still get useful content
  • Performance: Fast initial load with progressive enhancement

5. TypeScript Configuration for Val Town

Deno Configuration (deno.json)

{ "compilerOptions": { "noImplicitAny": false, "strict": true, "lib": ["dom", "dom.iterable", "deno.ns", "deno.unstable"] }, "lint": { "rules": { "exclude": ["no-explicit-any", "no-import-prefix"] } } }

Key Settings:

  • Deno-specific libs: Include deno.ns and deno.unstable
  • Import prefix rules: Exclude no-import-prefix to allow ESM.sh imports
  • Strict mode: Enable but allow any types where needed

6. TailwindCSS Integration

CDN-based Setup

<script src="https://cdn.twind.style" crossorigin></script>

Utility Classes in TSX

Create val
<div className="min-h-screen bg-black text-white font-mono p-4 flex items-center justify-center"> <div className="w-full max-w-2xl space-y-8"> {/* Content */} </div> </div>

7. File Organization Best Practices

Recommended Structure

├── index.html          # No-JS fallback + React container
├── index.tsx           # React app entry point
├── App.tsx             # Main component
├── deno.json           # Deno configuration
├── CRUSH.md            # Agent development guidelines
└── .gitignore          # Exclude .vt/, .crush/, etc.

File Naming Conventions

  • Entry points: index.tsx for React apps
  • Components: PascalCase (App.tsx, Header.tsx)
  • HTML: index.html as the primary file

8. Error Handling & Debugging

Platform Limitations

  • No console.log in production (use proper logging)
  • Limited debugging tools compared to traditional servers
  • Network requests must be HTTPS
  • No server-side file system access

Best Practices

  • Use try/catch for async operations
  • Provide user-friendly error messages
  • Test with vt status before pushing
  • Use vt tail to monitor logs in production

9. Performance Considerations

Optimization Techniques

  • Code splitting: Keep components focused and small
  • Lazy loading: Import components only when needed
  • Bundle size: Monitor via browser dev tools
  • Caching: Leverage browser caching for assets

Val Town Specific

  • Cold starts: First request may be slower
  • Memory limits: Be mindful of resource usage
  • Concurrent requests: Platform handles scaling automatically

10. Development Workflow

Local Development

# Check TypeScript compilation deno check # Run linter deno lint *.tsx # Test locally (serve static files) python -m http.server 8000

Deployment Cycle

  1. Make changes locally
  2. Test with deno check and deno lint
  3. Check vt status for pending changes
  4. vt push to deploy
  5. vt browse to verify deployment

11. Security Considerations

Best Practices

  • No secrets in code: Use environment variables
  • Input validation: Sanitize all user inputs
  • HTTPS only: All external requests must use HTTPS
  • CORS handling: Configure appropriate CORS headers

Val Town Specific

  • Environment variables: Access via Deno.env.get()
  • No file system access: Cannot read/write server files
  • Sandbox environment: Isolated execution context

12. Integration Patterns

API Endpoints

// HTTP endpoint val export default async function(req: Request): Promise<Response> { // Handle request return new Response("Hello World"); }

Cron Jobs

// Cron trigger val export default async function(): Promise<void> { // Scheduled task }

13. Tooling & CLI

VT Commands Mastered

  • vt status - Check deployment status
  • vt push - Deploy changes
  • vt pull - Sync remote changes
  • vt browse - Open in browser
  • vt create - Create new vals
  • vt clone - Clone existing vals

14. Common Pitfalls & Solutions

File Upload Issues

  • Binary files: Cannot upload binary files > certain size
  • Database files: SQLite files cannot be deployed
  • Empty files: Files must have content

Import Issues

  • Version pinning: Always pin dependency versions
  • ESM.sh URLs: Use full URLs for imports
  • Lint conflicts: Configure linter to allow Val Town patterns

React Specific

  • JSX transform: Must use @jsxImportSource
  • Component mounting: Use createRoot for React 18
  • Styling conflicts: TailwindCSS works but may need custom config

Key Takeaways

  1. Val Town is perfect for: Small web apps, APIs, scheduled tasks, and rapid prototyping
  2. React works great: With proper JSX configuration and pinned versions
  3. Progressive enhancement: Essential for accessibility and SEO
  4. Deployment is simple: Just vt push after local testing
  5. Platform limitations: Must design around serverless constraints
  6. TypeScript first: Strong typing is encouraged and well-supported
  7. ESM.sh ecosystem: Rich ecosystem of packages available via ESM.sh

Future Learning Areas

  • Advanced patterns: Custom hooks, context providers, routing
  • Database integration: Val Town's built-in SQLite support
  • Real-time features: WebSockets and server-sent events
  • Multi-val architectures: Coordinating between multiple vals
  • Performance optimization: Bundle analysis and code splitting
  • Testing strategies: Unit and integration testing approaches

Resources

  • Val Town Docs
  • ESM.sh - Package registry
  • TailwindCSS - Utility-first CSS
  • React 18 Docs - Latest React features

Documented on: 2025-01-19 Platform: Val Town Project: mcp2cli React TSX conversion skills/val-town-development.md

FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2025 Val Town, Inc.