Closed FreeJ1nG closed 5 months ago
Start a new pull request in StackBlitz Codeflow.
Currently, TS source code doesn't resolve aliases from compilerOptions.paths
too. If we do in the config, it'd need to align with the source code. But the discussions about that are at https://github.com/vitejs/vite/issues/6828, and at the moment we don't plan to support it. (However, there's still debate within the team if this is something we actually want)
If we do in the config, it'd need to align with the source code
What does this mean again?
If tsconfig alias would work in a config file, it should also work in your source code files for consistency.
If tsconfig alias would work in a config file, it should also work in your source code files for consistency.
But technically it does work if resolve.alias
is added right?
i feel like support for tsconfig paths in vite.config.ts is a different issue that currently doesn't have an easy workaround? (cmiiw)
However, there's still debate within the team if this is something we actually want
What is the consideration for the vite team to add/not add this feature?
i dont know if this work, but what about execute the vite.config.{ts,js}
with esbuild-register
or swc-register
or maybe ts-node
?
i dont know if this work, but what about execute the
vite.config.{ts,js}
withesbuild-register
orswc-register
or maybets-node
?
The vite config is usually used by vite's server, e.g. executing vite
(dev server) or vite build
, so it's probably not viable to use ts-node since it's we're not trying to run vite.config.ts
in isolation
Unless you mean transpiling vite.config.ts
to resolve it's paths first, but that also has it's own problems like files not getting run through the vite plugin pipeline, etc.
CMIIW
But technically it does work if
resolve.alias
is added right?
Yes, but resolve.alias
has different resolve behaviour compared to tsconfig paths. Tsconfig paths is more lax and could map to more paths than intended, but will still cover the resolve.alias
behaviour. If we support tsconfig paths in the config, we're supporting more than what resolve.alias
covers.
i feel like support for tsconfig paths in vite.config.ts is a different issue that currently doesn't have an easy workaround? (cmiiw)
I think you can still use relative imports?
What is the consideration for the vite team to add/not add this feature?
There's still mixed opinions about this. My opinion is https://x.com/robpalmer2/status/1770612164396515667 and the result in https://github.com/vitejs/vite/issues/6828#issuecomment-1635430095. Others think that supporting tsconfig alias would be convenient and rustifying the resolver would solve the performance issue, and that vite-tsconfig-paths
had millions of downloads per month (people want it).
having this ability would be great, especially in a nx monorepo.
i usually need to call certain functions in from other packages in the vite.config.ts
Closing this as it's something we don't plan on supporting for now.
Description
Some plugin configurations require a complex object that might be split across the codebase For instance, CRXJS Vite Plugin requires a
manifest.json
file, which might/might not require an (possible aliased) import from another fileReproduction link here
Right now, vite does not resolve alias paths within vite.config.ts or it's dependencies
Example of such case:
Example of another case:
Both cases will throw error when running an instance of the vite server
Suggested solution
Maybe consider using
compilerOptions.paths
to resolve the imports invite.config.ts
somewhere in the plugin pipelineAlternative
I'm also considering creating a plugin that creates a workaround, still not 100% sure on how to accomplish this though
Additional context
I've received quite a bit of concern and confusion regarding consumers of vite not being able to utilize aliases in
vite.config.ts
, and I believe it'd be an issue worth looking atValidations