Skip to content

Importing from src directly instead of from ~/src or @/src #103

Answered by ElMassimo
theodoretliu asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Theodore!

You could add a new alias using resolve.alias for every root folder that you are referencing in the imports. For example:

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 ~/ and @/ aliases in webpack and jest.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ElMassimo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants