New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possibility to define additional node paths #8439
Comments
|
If you set |
|
@sapphi-red
Which is not the case in my setup.. the root directory is not |
|
May I ask you why you don't want to move root directory to |
|
The question is just whether this property was made for this purpose, or whether its just a side effect of it. The default vue template for example has this config: export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});To achieve the effect I want to have, its using an alias. |
|
The equivalent of the rollup/esbuild/webpack feature noted in Vite is |
|
@bluwy Thanks for your reply! I would have even more usecases for the |
Mostly because
I think both. And with plugins like https://github.com/Subwaytime/vite-aliases should cover the heavylifting too. Usually I'd alias |
|
Closing as we don't want to introduce new options that do similar things. |
|
For those of us trying to make the migration from create-react-app where having absolute imports without any kind of alias was easy and widely used, this is painful. Yes I can create an I feel like I've gotta be missing something here. |
|
For anyone finding this issue while migrating away from CRA, it appears vite-tsconfig-paths solves the issue of alias-free absolute imports. |
Clear and concise description of the problem
I've tried to replace my current bundler (rollup) with
viteand got stuck with path resolution.My setup is quite basic. I'm using absolute import paths in my project:
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 themoduleDirectoriesprop from the@rollup/plugin-node-resolve. Unfortunatelyviteisn'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:
This is also supported by
Eslintwith the eslint-import-resolver-node plugin (moduleDirectoryoption)Suggested solution
Provide this feature "natively" in the vite config. Something like
resolve.moduleDirectoriesorresolve.nodePaths.Alternative
It seems like you can use the
@rollup/plugin-node-resolveplugin 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
The text was updated successfully, but these errors were encountered: