Skip to content

Use sv create my-app para criar um projeto SvelteKit com a CLI do SvelteKit. Responda às perguntas para selecionar um template e configurar seu ambiente de desenvolvimento.

sh
bunx sv create my-app
txt
┌  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!

Uma vez que o projeto é inicializado, mude para o novo diretório. Você não precisa executar bun install pois as dependências já estão instaladas.

Em seguida, inicie o servidor de desenvolvimento com bun --bun run dev.

Para executar o servidor de desenvolvimento com Node.js em vez de Bun, você pode omitir a flag --bun.

sh
cd my-app
bun --bun run dev
txt
  $ 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 help

Visite http://localhost:5173 em um navegador para ver a aplicação template.


Se você editar e salvar src/routes/+page.svelte, deverá ver suas alterações recarregadas automaticamente no navegador.


Para build de produção, você precisará adicionar o adapter correto do SvelteKit. Atualmente recomendamos o svelte-adapter-bun.

sh
bun add -D svelte-adapter-bun

Agora, faça as seguintes alterações no seu svelte.config.js.

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 = {
  // Consult https://svelte.dev/docs/kit/integrations#preprocessors
  // for more information about preprocessors
  preprocess: vitePreprocess(),

  kit: {
    // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
    // If your environment is not supported, or you settled on a specific environment, switch out the adapter.
    // See https://svelte.dev/docs/kit/adapters for more information about adapters.
    adapter: adapter(),
  },
};

export default config;

Para build de produção:

sh
bun --bun run build
txt
  $ 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

Consulte a documentação do SvelteKit para documentação completa.

Bun by www.bunjs.com.cn edit