-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
-
Hi all,
I'm migrating our app from Webpack to Vite and have run into a challenge with alias resolution.
Our project consists of more than 10 entry points (essentially, different apps that share some core functionality). Each entry point needs to resolve certain aliases differently. For example, the account alias should point to a different directory depending on which app is being built or served (depending on entry point).
With Webpack, we could handle this by dynamically generating the config and serving all entry points from a single dev server. In Vite, the config is static per process, and it seems aliases are resolved globally at server startup, not per entry point.
Is it possible in Vite to resolve an alias like this based on the entry point?
resolve: {
alias: {
`account`: path.resolve(__dirname, 'src/apps/app1'), // Ideally, 'app1' would be dynamic, depending on the entry point
},
},
For example:
For entry point 1, import abc from 'account/some/folder'; should resolve to src/apps/app1/some/folder
For entry point 2, the same import should resolve to src/apps/app2/some/folder
Key requirements:
- Each entry point (account) should have its own alias resolution for org.
- Ideally, we’d like to run multiple entry points in parallel for local development (as we did with Webpack).
- We want to avoid running 10+ separate Vite dev servers if possible, due to resource and workflow concerns.
Is there a recommended way to achieve per-entry-point alias resolution in Vite? Or any best practices for multi-app setups like this?
Thanks in advance!
Beta Was this translation helpful? Give feedback.