• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
matthewmateo

matthewmateo

pala-component-library

Public
Like
pala-component-library
Home
Code
7
backend
1
components
2
.vtignore
AGENTS.md
README.md
deno.json
H
main.ts
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
/
README.md
Code
/
README.md
Search
11/9/2025
Viewing readonly version of main branch: v39
View latest version
README.md

Svelte Component Library for Val Town

A reusable Svelte component library that compiles components on-demand and serves them as ES modules.

Architecture

This library serves compiled Svelte components via an HTTP endpoint. Components are:

  • Stored as .svelte files in the components/ directory
  • Compiled on-demand using the Svelte compiler
  • Imports rewritten to use CDN URLs (esm.sh) for Svelte runtime
  • Cached for performance
  • Served as ES modules that can be imported anywhere

Project Structure

├── backend/
│   └── index.ts           # HTTP endpoint (Hono app)
├── components/
│   └── button/
│       └── Button.svelte  # Example component
└── README.md

Usage

1. Deploy to Val Town

  1. Create a new HTTP val in Val Town
  2. Copy the contents of backend/index.ts to your val
  3. Create the component files in the Val Town file system using the file editor

2. Import Components

Once deployed, you can import components in your pala blocks or other projects:

// Import the compiled component import Button from 'https://your-username-componentlib.web.val.run/button' // Use it in your Svelte app <Button variant="primary" size="medium">Click me</Button>

Adding New Components

  1. Create a new folder in components/ with your component name (lowercase)
  2. Create a .svelte file with the capitalized component name

Example for a Card component:

components/
└── card/
    └── Card.svelte
  1. The component will automatically be available at /card

Component Example

<script> export let variant = 'primary' export let disabled = false </script> <button class="{variant}" {disabled}> <slot>Default text</slot> </button> <style> button { padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; } .primary { background: #0066ff; color: white; } </style>

Development

Local Development

  1. Install Deno
  2. Run the server:
    deno run --allow-net --allow-read backend/index.ts

Development Endpoints

These endpoints are available for development purposes:

  • POST /cache/clear - Clear all cached components
  • POST /cache/clear/:component - Clear cache for specific component

Example:

curl -X POST https://your-val.web.val.run/cache/clear/button

Configuration

The Svelte compiler is configured with:

  • format: 'esm' - ES module output
  • generate: 'dom' - Client-side rendering
  • css: 'injected' - CSS is injected into the component (no separate stylesheet needed)

After compilation, imports like import { ... } from 'svelte/internal' are rewritten to import { ... } from 'https://esm.sh/svelte@4.2.8/internal' so they can be resolved by the browser or other environments.

You can modify these options in backend/index.ts in the compile_component function.

Caching

Compiled components are cached in memory to improve performance. The cache persists for the lifetime of the val instance.

Notes

  • Components are compiled at runtime on first request
  • Svelte runtime dependencies are imported from esm.sh CDN
  • Subsequent requests are served from cache
  • Val Town's serverless environment may clear the cache between cold starts
  • For production use, consider pre-compiling components or implementing persistent caching
FeaturesVersion controlCode intelligenceCLIMCP
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.