How to use absolute Imports using React with Ts and Vite

today I am going to talk about How to use absolute Imports using React with Ts and Vite using react-ts with Vite

as you can see here I am using … to find the path of components in order to use them, it looks fine since I do not have deep path.


This content originally appeared on DEV Community and was authored by Abdeldjalil Hachimi

today I am going to talk about How to use absolute Imports using React with Ts and Vite using react-ts with Vite

as you can see here I am using ... to find the path of components in order to use them, it looks fine since I do not have deep path.

Image description

to sum up in order to avoid it you can easily use this in your
tsconfig.json

"compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "~/*": ["./*"]
    },
}

Image description

and after that go to vite.config.ts

  resolve: {
    alias: {
      '~': path.resolve(__dirname, 'src'),
    },
  },

Image description

and it's done

Thanks for reading this article and if you have any suggestions you are welcome


This content originally appeared on DEV Community and was authored by Abdeldjalil Hachimi


Print Share Comment Cite Upload Translate Updates
APA

Abdeldjalil Hachimi | Sciencx (2022-02-04T16:54:46+00:00) How to use absolute Imports using React with Ts and Vite. Retrieved from https://www.scien.cx/2022/02/04/how-to-use-absolute-imports-using-react-with-ts-and-vite/

MLA
" » How to use absolute Imports using React with Ts and Vite." Abdeldjalil Hachimi | Sciencx - Friday February 4, 2022, https://www.scien.cx/2022/02/04/how-to-use-absolute-imports-using-react-with-ts-and-vite/
HARVARD
Abdeldjalil Hachimi | Sciencx Friday February 4, 2022 » How to use absolute Imports using React with Ts and Vite., viewed ,<https://www.scien.cx/2022/02/04/how-to-use-absolute-imports-using-react-with-ts-and-vite/>
VANCOUVER
Abdeldjalil Hachimi | Sciencx - » How to use absolute Imports using React with Ts and Vite. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/04/how-to-use-absolute-imports-using-react-with-ts-and-vite/
CHICAGO
" » How to use absolute Imports using React with Ts and Vite." Abdeldjalil Hachimi | Sciencx - Accessed . https://www.scien.cx/2022/02/04/how-to-use-absolute-imports-using-react-with-ts-and-vite/
IEEE
" » How to use absolute Imports using React with Ts and Vite." Abdeldjalil Hachimi | Sciencx [Online]. Available: https://www.scien.cx/2022/02/04/how-to-use-absolute-imports-using-react-with-ts-and-vite/. [Accessed: ]
rf:citation
» How to use absolute Imports using React with Ts and Vite | Abdeldjalil Hachimi | Sciencx | https://www.scien.cx/2022/02/04/how-to-use-absolute-imports-using-react-with-ts-and-vite/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.