I'm setting up a monorepo workspace for a Vue 3 (vite + ts), cloud functions, & shared-lib (shared functions and ts interfaces etc.).
I can get the import of my local shared-lib folder to work. I get live type-checking in my front-end project by doing a npm run build -- -- watch on my shared-lib.
Yet for some reason, everything that is transpiled to Javascript, doesn't update unless I uninstall and then install the shared-lib package.
So for instance: creating a const in the shared-lib, doesnt make it usable in the front-end / back-end projects where I'm importing the shared-lib. But creating an interface, IS.
I tried a couple of things and searched a large part of the internet . I tried to play around with the vite.config since I thought that it might do some sort of caching on the packages.
For now, this is what my vite.config.ts looks like:
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
// https://vitejs.dev/config/
export default defineConfig({
server: {
host: true,
},
plugins: [vue()],
resolve: {
preserveSymlinks: true,
},
optimizeDeps: {
include: ["shared-lib"],
},
})
This is the index.ts in my shared-lib:
// this is not usable / doesn't update live.
export const sharedConst = () => console.log("testing shared functionality")
// this updates live in other projects.
export interface TestInterface {
name: {
firstName: string
lastName: string
}
}
This is what my package.json dependencies look like in my front-end:
"dependencies": {
...
"shared-lib": "file:../backend/functions/dist/shared-lib"
},
I build the shared-lib to the dist folder of my cloud functions in order to have it be packaged when I upload it. Vue/vite doesn't care where it's packages reside.