Use Svelte with Jeasx
Svelte is a UI framework with a compiler: you write components in HTML, CSS and JavaScript, and Svelte turns them into small bundles that do little work in the browser. Jeasx renders them on the server and hydrates them in the browser.
How do I integrate Svelte with Jeasx?
Install Svelte and its esbuild plugin:
npm install svelte esbuild-svelte
Then register the plugin for the server and the browser build in jeasx.config.js:
export default {
// The server imports this config at startup too, so import build-only plugins lazily:
// loading the Svelte compiler would slow down every server start.
ESBUILD_SERVER_OPTIONS: async () => {
const { default: sveltePlugin } = await import("esbuild-svelte");
return {
plugins: [sveltePlugin({ compilerOptions: { generate: "server", css: "external" } })],
};
},
ESBUILD_BROWSER_OPTIONS: async () => {
const { default: sveltePlugin } = await import("esbuild-svelte");
return {
plugins: [sveltePlugin({ compilerOptions: { generate: "client", css: "external" } })],
};
},
};
With css: "external", the styles of all components imported by a browser bundle end up in a CSS file next to it (e.g. index.css next to index.js). Link it in your page, so the components are styled right away, even before hydration and without JavaScript.
View the source code of this page for an implementation of a Svelte integration with hydration support. Feel free to improve it as you like.
Holo card
Move the pointer over the card. Two Springs from svelte/motion follow it, so the tilt and the foil glare glide instead of jumping, and style: directives feed them into CSS.
Budget
Drag the sliders to set the monthly budget and the spending per category: $derived sums up the spending, and Tween.of animates the number and the donut ring towards each new value.
Quiz
{#key} recreates the question on every step, so fly transitions slide the old one out and the new one in, and the result pops up with scale.