Syn
The Bundler for Browsers
Install / Use
/learn @kat-tax/SynREADME
SYN
The Web Bundler for Web Environments
Definition:
/**
* Bundle a React application
* @param entry Path to the app entry point (e.g. /index.tsx)
* @param files Virtual File System containing files needed to bundle the app
* @param config ESBuild config https://esbuild.github.io/api/#bundle
* @param importMap The import map used to determine external dependencies
* @returns a string containing the bundled application code
*/
export async function bundle(
entry: string,
files: Map<string, string | Uint8Array>,
config?: BuildOptions,
importMap?: Record<string, string>,
): Promise<string> {
const resolver = new Resolver(files);
const compiler = new Compiler();
return await compiler.compile(entry, {
define: {'process.env.NODE_ENV': '"development"'},
inject: ['import-react'],
jsx: 'automatic',
target: 'esnext',
format: 'esm',
jsxDev: true,
...config,
}, [
png({resolver}),
svg({resolver}),
css({resolver}),
react({resolver, importMap}),
]);
}
Usage:
// Import bundler
import {bundle} from 'syn-bundler';
// Create a Virtual File System
const files: Map<string, string | Uint8Array> = new Map();
// Add code to VFS
for (const [name, component] of Object.entries(components)) {
files.set(`/components/${name}`, component.code);
}
// Add assets to VFS
for (const [name, asset] of Object.entries(assets)) {
const extension = asset.isVector ? 'svg' : 'png';
const folder = asset.isVector ? 'vectors' : 'rasters';
const path = `/assets/${folder}/${name}.${extension}`;
files.set(path, asset.bytes);
}
// Add entrypoint to VFS
files.set('/index.tsx', mainComponent);
// Bundle VFS
const output = await bundle('/index.tsx', files);
// Print string output (or render in iframe)
console.log(output);
Related Skills
node-connect
347.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
