Back to Turborepo

SvelteKit

apps/docs/content/docs/guides/frameworks/sveltekit.mdx

2.9.92.8 KB
Original Source

SvelteKit is a framework for rapidly developing robust, performant web applications using Svelte.

Quickstart

To get started with SvelteKit in a Turborepo quickly, use the with-svelte example:

<PackageManagerTabs> <Tab value="pnpm">
bash
pnpm dlx create-turbo@latest -e with-svelte
</Tab> <Tab value="yarn">
bash
yarn dlx create-turbo@latest -e with-svelte
</Tab> <Tab value="npm">
bash
npx create-turbo@latest -e with-svelte
</Tab> <Tab value="bun">
bash
bunx create-turbo@latest -e with-svelte
</Tab> </PackageManagerTabs>

Adding a SvelteKit application to an existing repository

Use npm create svelte to set up a new SvelteKit application in a package. From the root of your repository, run:

<PackageManagerTabs> <Tab value="pnpm">
bash
pnpm dlx sv create
</Tab> <Tab value="yarn">
bash
yarn dlx sv create
</Tab> <Tab value="npm">
bash
npx sv create
</Tab> <Tab value="bun">
bash
bunx sv create
</Tab> </PackageManagerTabs>

Integrating with your repository

To add Internal Packages to your new application, install them into the app with your package manager:

<PackageManagerTabs> <Tab value="pnpm">
diff
{
  "name": "my-app",
  "dependencies": {
+   "@repo/ui": "workspace:*"
  }
}
</Tab> <Tab value="yarn">
diff
{
  "name": "my-app",
  "dependencies": {
+   "@repo/ui": "*"
  }
}
</Tab> <Tab value="npm">
diff
{
 "name": "my-app",
  "dependencies": {
+   "@repo/ui": "*"
  }
}
</Tab> <Tab value="bun">
diff
{
 "name": "my-app",
  "dependencies": {
+   "@repo/ui": "workspace:*"
  }
}
</Tab> </PackageManagerTabs>

Make sure to run your package manager's install command. You also may need to update scripts in package.json to fit your use case in your repository.

Customizing tasks

By default, the new application will use the tasks defined in the root turbo.json. If you'd like to configure tasks differently for the new application, use Package Configurations.

Microfrontends

When using Svelte with Turborepo's microfrontends, make sure to set the base property for child applications. This ensures the assets like images and CSS will be routed to the correct application.

ts
import { defineConfig } from "vite";

export default defineConfig({
  base: "/admin",
});