Usa sv create my-app per creare un progetto SvelteKit con la CLI SvelteKit. Rispondi alle domande per selezionare un template e configurare il tuo ambiente di sviluppo.
bunx sv create my-app┌ Welcome to the Svelte CLI! (v0.5.7)
│
◇ Which template would you like?
│ SvelteKit demo
│
◇ Add type checking with Typescript?
│ Yes, using Typescript syntax
│
◆ Project created
│
◇ What would you like to add to your project?
│ none
│
◇ Which package manager do you want to install dependencies with?
│ bun
│
◇ Successfully installed dependencies
│
◇ Project next steps ─────────────────────────────────────────────────────╮
│ │
│ 1: cd my-app │
│ 2: git init && git add -A && git commit -m "Initial commit" (optional) │
│ 3: bun run dev -- --open │
│ │
│ To close the dev server, hit Ctrl-C │
│ │
│ Stuck? Visit us at https://svelte.dev/chat │
│ │
├──────────────────────────────────────────────────────────────────────────╯
│
└ You're all set!Una volta inizializzato il progetto, cd nella nuova directory del progetto. Non devi eseguire bun install poiché le dipendenze sono già installate.
Poi avvia il server di sviluppo con bun --bun run dev.
Per eseguire il server di sviluppo con Node.js invece di Bun, puoi omettere il flag --bun.
cd my-app
bun --bun run dev $ vite dev
Forced re-optimization of dependencies
VITE v5.4.10 ready in 424 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ press h + enter to show helpVisita http://localhost:5173 in un browser per vedere l'app template.
Se modifichi e salvi src/routes/+page.svelte, dovresti vedere le tue modifiche ricaricate a caldo nel browser.
Per la build di produzione, dovrai aggiungere l'adapter SvelteKit corretto. Attualmente consigliamo
bun add -D svelte-adapter-bun.
Ora, apporta le seguenti modifiche al tuo svelte.config.js.
import adapter from "@sveltejs/adapter-auto";
import adapter from "svelte-adapter-bun";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consulta https://svelte.dev/docs/kit/integrations#preprocessors
// per ulteriori informazioni sui preprocessori
preprocess: vitePreprocess(),
kit: {
// adapter-auto supporta solo alcuni ambienti, vedi https://svelte.dev/docs/kit/adapter-auto per un elenco.
// Se il tuo ambiente non è supportato o hai scelto un ambiente specifico, cambia l'adapter.
// Vedi https://svelte.dev/docs/kit/adapters per ulteriori informazioni sugli adapter.
adapter: adapter(),
},
};
export default config;Per costruire un bundle di produzione:
bun --bun run build $ vite build
vite v5.4.10 building SSR bundle for production...
"confetti" is imported from external module "@neoconfetti/svelte" but never used in "src/routes/sverdle/+page.svelte".
✓ 130 modules transformed.
vite v5.4.10 building for production...
✓ 148 modules transformed.
...
✓ built in 231ms
...
✓ built in 899ms
Run npm run preview to preview your production build locally.
> Using svelte-adapter-bun
✔ Start server with: bun ./build/index.js
✔ done