One way to go about it is to use turborepo.
Simple rule to follow:
Apps and sites go to apps folder and libraries and configs go to packages folder.
npx create-turbo@latest
When adding packages make sure they follow npm package guidelines and have package.json so it can be imported in apps. Here is the example of package.json for my stub svelte library uikit:
{
“name”: “uikit”,
“version”: “0.0.0",
“main”: “./index.svelte”,
“types”: “./index.svelte”,
“devDependencies”: {
“svelte”: “^3.44.0”
}
}
After adding apps and packages we need to configure turbo config located in turbo.json. I only had to append the svelte-kit command in the outputs for build:
{
“pipeline”: {
“build”: {
“dependsOn”: [“^build”],
“outputs”: [“dist/**“, “.next/**“, “svelte-kit/**“]
},
“lint”: {
“outputs”: []
},
“dev”: {
“cache”: false
}
}
}
Than you can import svelte components in your sveltkit app like this:
<script>
import Button from “uikit”
</script>
<Button> Test Button </Button>
Next you need to set up different ports for each repository from “apps” folder so we can run all the sites simultaneously. This might be quite handy for some use cases. Update dev command script located in the root of the site in their respective package.json:
“scripts”: {
“dev”: “svelte-kit dev --port 3003”,
...
That should be it; start developing!
npm run dev
This will spawn all of the apps in the project on their designated ports.
npm run build
You must be wandering where do you run this commands since each lib or app will have its own package.json?
Run all the commands in the root of the monorepo. Turborepo is taking care of it.
You can read more about it here https://turborepo.org/
Also here is the repo example with both svelte and react libs/apps in the same monorepo here https://nenadkostic.com/blog/turborepo-sveltekit/