How to point aliases to to different locations based on where it's used on a monorepo

Viewed 371

I working on a monorepo project based on Yarn Workspaces with the following structure and I'm wondering how can I use alias with vite to use the same alias name, for example "@composables" to point to a different locations depending on the local repo it's called from. so for example if i have 2 packages the "@composables" should point to "/package-a/composables/" if i used it inside package-a and should point to /package-b/composables/" if i used it in a vue component inside package-b.

I tried using the following but it didn't resolve to the correct location

resolve: {
    alias: [
        { find: '@composables', replacement: './composables.json' },
    ],
  },

And this is the project structure

project-root/
   vite.config.ts
    packages/
        package-a/
        tsconfig.json
            src/
               composables/
               index.ts
            ....
        package-b/
            src/
               composables/
               index.ts
            tsconfig.json
             ...
             ```
0 Answers
Related