استخدم sv create my-app لإنشاء مشروع SvelteKit مع SvelteKit CLI. أجب على الأسئلة لتحديد قالب وإعداد بيئة التطوير الخاصة بك.
sh
bunx sv create my-apptxt
┌ 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!بمجرد تهيئة المشروع، cd إلى المشروع الجديد. لا تحتاج إلى تشغيل 'bun install' لأن التبعيات مثبتة بالفعل.
ثم ابدأ خادم التطوير باستخدام bun --bun run dev.
لتشغيل خادم التطوير باستخدام Node.js بدلاً من Bun، يمكنك حذف العلم --bun.
sh
cd my-app
bun --bun run devtxt
$ 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زر http://localhost:5173 في متصفح لرؤية تطبيق القالب.
إذا قمت بتحرير وحفظ src/routes/+page.svelte، يجب أن ترى تغييراتك يتم إعادة تحميلها ساخنًا في المتصفح.
للبناء للإنتاج، ستحتاج إلى إضافة محول SvelteKit الصحيح. نوصي حاليًا بـ
bun add -D svelte-adapter-bun.
الآن، قم بإجراء التغييرات التالية على 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;لبناء حزمة إنتاج:
sh
bun --bun run buildtxt
$ 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