Possibility to define additional node paths
See original GitHub issueClear and concise description of the problem
I’ve tried to replace my current bundler (rollup) with vite
and got stuck with path resolution.
My setup is quite basic. I’m using absolute import paths in my project:
import { something } from 'someDir/someFile';
The relative file system path of this import would be ./src/someDir/someFile
.
As you can see, I can omit the ./src/
part here. I did this by using the moduleDirectories
prop from the @rollup/plugin-node-resolve
. Unfortunately vite
isn’t providing this functionality out of the box which is in my opinion a key feature for every bundler.
Bundlers which are providing this feature:
- Webpack with resolve.modules
- esbuild with nodePaths
- Rollup with @rollup/plugin-node-resolve and moduleDirectories
This is also supported by Eslint
with the eslint-import-resolver-node plugin (moduleDirectory
option)
Suggested solution
Provide this feature “natively” in the vite config. Something like resolve.moduleDirectories
or resolve.nodePaths
.
Alternative
It seems like you can use the @rollup/plugin-node-resolve
plugin here, but it still feels weird to have this key feature not supported. Additionally since vite is doing quite some resolve logic itself I’m in fear of something not working properly by using the plugin.
You could also use aliases, but is this the “right” way? - With this solution I would be forced to rewrite all of my imports.
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Mostly because
resolve.alias
already covers a lot of base, and Vite is trying to minimize the config surface area.I think both. And with plugins like https://github.com/Subwaytime/vite-aliases should cover the heavylifting too.
Usually I’d alias
src
as@
and call it a day, as there’s no need to add more complexity for code preference. But the option is always available with plugins 🙂@bluwy Thanks for your reply! As you can imagine, aliasing every directory under
./src
manually is not really the way to go for me. Can you elaborate on why you think Vite shouldn’t provide any other way of resolving? (Do you think this should be handled by plugins or do you think the current feature set is enough?)…I would have even more usecases for the
moduleDirectories
feature I described.