How to use alias paths in Typescript & ViteJS

Oscar de la Hera Gomez
Three flowers that represent React, ThreeJS and ViteJS side by side beneath them sits the text "Alias Paths."

To use typescript path aliases in Typescript & ViteJS, setup your paths in the TSConfig and match them in the vite.config.js.

The solution that we carried out below can be found on the main branch of our Open Source React, Typescript & ViteJS Starter Project.

git clone git@github.com:delasign/reactjs-3js-vitejs-starter-project.git

Step One: Setup the Project

A screenshot of Chrome showing that the plane is now using the shader that we offer in this tutorial.

Follow the tutorial below to learn how to setup a Typescript & ViteJS project that works with a GLSL shader.

Step Two: Add Dependencies

A screenshot of Terminal showing you how to add the Path dependency.

In Terminal, with the current directory set to that of the project, add the path dependency using the line below:

yarn add path

Step Two: Add the Paths to the TSConfig

A screenshot of the TSConfig showing you how we added the paths.

In the tsconfig.json file, add the relevant paths.

Step Three: Add the Paths to the Vite Config

A screenshot showing the TSConfig and Vite Config side by side, highlighted are how the paths match and the syntax that you have to use in each file.

In the vite.config.ts file, add the relevant paths using the alias parameter within the resolve attribute of the defaultConfig.

Step Four: Update Paths

A screenshot of VSCode showing you how we updated the Paths of imports within a TSX file and how they now work.

The project can now use these paths. Update them wherever necessary.

Step Five: Test

A screenshot of Chrome showing that the plane is now using the shader that we offer in this tutorial.

Run the project and make sure everything works as expected.

Looking to learn more about ReactJS and ThreeJS ?

Search our blog to find educational content on learning how to use ReactJS and ThreeJS.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details