Search code examples
sveltemonoreposveltekitturborepo

How to setup turborepo with sveltekit and pnpm


I am trying to add Turborepo to my Svelte apps but looks like the npx create-turbo@latest command and also the examples currently only support NextJs. How can I configure it to work Svelte and Sveltekit apps?


Solution

  • After creating the project with turborepo starter you have to follow this simple rule:

    Apps and sites go to apps folder and libraries and configs go to packages folder.

    Now you can create a few sveltekit apps in apps folder using sveltekit starter and create a plain svelte library in packages folder. I wrote a small blog post about it with the code example here

    Few notes: Make sure you have package.json for the lib project, example:

    {
    “name”: “uikit”,
    “version”: “0.0.0",
    “main”: “./index.svelte”,
    “types”: “./index.svelte”,
    “devDependencies”: {
        “svelte”: “^3.44.0”
    }
    

    }

    Update turbo config in turbo.json file to contain the svelte-kit command:

    {
      “pipeline”: {
        “build”: {
          “dependsOn”: [“^build”],
          “outputs”: [“dist/**“, “.svelte-kit/**“, “.svelte/**“]
        },
        “lint”: {
          “outputs”: []
        },
        “dev”: {
          “cache”: false
        }
      }
    }
    

    Update ports for each svelte kit app in the package.json script block. Run your commands from the root of the monorepo.

    npm run dev
    

    and you shall have all the apps running simultaneously or if you wish to build all at once just do

    npm run build