Better Programming

Advice for programmers.

Follow publication

Member-only story

The Right Usage of Aliases in Webpack and TypeScript

Oleh Zaporozhets
Better Programming
Published in
3 min readApr 5, 2020

Photo by Florian Olivo on Unsplash

Hello, world!

Today I want to share some tips with you to improve your projects and make it much easier to maintain. I’m talking about aliases.

Explanation

If you’ve never heard of aliases you’ll find this section useful.

According to the dictionary, an alias is a name that a person assumes for a particular purpose. We can give aliases to our files or even folders in our project. As usual, more information can be found in the documentation.

Aliases in Webpack

Assume we have a folder structure like this:

From the structure above we can see, If we need content from thegetUserId.ts file, as we can see from the structure above.

For index.ts it looks like this:

For user.ts it looks like this:

OK, this isn’t a big deal — we can solve it with webpack aliases in our webpack.config.js:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in