esbuild plugin that resolves and compiles .svelte files for bundling with esbuild. Current stable version 0.9.4, actively maintained. Supports Svelte 4 and 5 (peer dep range >=4.2.1 <6). Key differentiators: zero-config setup for CSS handling (external by default, can inject), built-in caching for incremental builds, and full support for Svelte preprocessors including TypeScript. Compared to alternatives like svelte-loader for webpack or vite-plugin-svelte, this plugin is tailored for esbuild's speed and simplicity, with minimal dependencies and straightforward API.
npm install esbuild-svelteVerified import paths — ran on the pinned version, not inferred.
Shows minimal esbuild build script with sveltePlugin, including required mainFields and conditions for Svelte component resolution.
Upgrade Svelte to >=4.2.1 and Node to >=18.
Set compilerOptions.css: 'external' to emit external CSS, or 'injected' to include in JS.
Add 'svelte' to conditions and 'svelte' to mainFields in esbuild build options.
Use a separate dev server like sirv and configure esbuild in watch mode, or consider vite-plugin-svelte for dev experience.
Explicitly set compilerOptions.css if default behavior matters.
Change to: import sveltePlugin from 'esbuild-svelte';
Use ESM import or use require('esbuild-svelte').default.Run 'npm install esbuild-svelte' and ensure Node >=18.
Run 'npm install svelte@^4.2.1'.
Remove vite-plugin-svelte from plugins array when using esbuild-svelte.