Importing from src
directly instead of from ~/src
or @/src
#103
-
Hi! Thank you so much for this amazing project, it's worked very well for me so far. To make my adoption of Vite more gradual, I wanted to make the Javascript files interpretable by both Is there a way to configure absolute imports so that they don't require a new prefix? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi Theodore! You could add a new alias using import { resolve } from 'path'
import { defineConfig } from 'vite'
export default defineConfig({
resolve: {
alias: {
'src/': `${resolve(__dirname, 'app/src')}/`,
},
},
}) I don't recommend this though. A more robust approach would be to define |
Beta Was this translation helpful? Give feedback.
Hi Theodore!
You could add a new alias using
resolve.alias
for every root folder that you are referencing in the imports. For example:I don't recommend this though.
A more robust approach would be to define
~/
and@/
aliases in webpack and jest.