Custom Assets Handling#
Configure custom asset types for your Jac Client build process to support Web Workers, Python scripts, and other specialized file types.
Overview#
By default, Jac Client handles common asset types like images, fonts, and CSS files. With custom asset configuration, you can extend this to include any file type, such as .js, .py, .wasm, or .json.
Quick Start#
Configuration Location#
Custom asset extensions are configured under [plugins.client.assets] in your jac.toml:
[project]
name = "my-app"
version = "1.0.0"
entry-point = "main.jac"
[plugins.client.assets]
custom_extensions = [".js", ".py"]
Basic Example: Web Workers#
Project Structure:
my-jac-project/
├── jac.toml
├── main.jac
└── assets/
└── workers/
├── worker.js # JavaScript Web Worker
└── worker.py # Python code for Pyodide
Configuration Structure#
Asset Configuration Keys#
custom_extensions (Array of Strings)#
Specify file extensions to treat as copyable assets:
Default Asset Types (always supported):
- Images:
.png,.jpg,.jpeg,.gif,.webp,.svg,.ico - Fonts:
.woff,.woff2,.ttf,.otf,.eot - Media:
.mp4,.webm,.mp3,.wav - Styles:
.css
Custom extensions are additive, they don't replace default types.
How It Works#
Build Process Workflow#
1. Developer adds custom_extensions to jac.toml
↓
2. Assets placed in assets/ directory
↓
3. Build process reads config via get_config()
↓
4. AssetProcessor copies matching files to build/assets/
↓
5. Server dynamically routes custom asset types
↓
6. Assets accessible via /path/to/asset.ext
Custom assets are copied to .jac/client/build/assets/ and served from their relative paths.
Use Cases#
- Web Workers with Python Backend: Enable multi-threaded processing using JavaScript Web Workers with Python via Pyodide.
- Configuration Files: Serve JSON configuration files as static assets.
- WebAssembly Modules: Serve
.wasmfiles for high-performance computations.
Related Documentation#
- Configuration Overview - Complete configuration guide
- Custom Configuration - Vite and TypeScript configuration
- Package Management - Manage npm dependencies
- All-in-One Example - Working example with Web Workers