DEV Community

Discussion on: No More ../../../ Import in React

Collapse
 
imsalehmuhammad profile image
Saleh Muhammad

Nice one, But i think this approach is good when you are the only one maintainer of the codebase. For the whole team would suggest using webpack alias.

webpack.js.org/configuration/resol...

Collapse
 
nilanth profile image
Nilanth • Edited

I think it can be used with n number of maintainer or n number of team also.
As the Package with largest react community also uses this approach.
FYR: github.com/ant-design/ant-design

Collapse
 
natevictor profile image
Nathan Victor

You are correct, and the 5-line setting is tidy and simple. Either way, a team of any size would be using the same settings.

Collapse
 
aymenmarouani profile image
Aymen Marouani

Thanks for the tip, but how can I add this webpack alias when using create-react-app ?

Collapse
 
nilanth profile image
Nilanth

webpack alias not required for CRA. Above config is enough for CRA.

Thread Thread
 
aymenmarouani profile image
Aymen Marouani

There's also a library called craco that can override configuration for CRA

Collapse
 
gdenn profile image
Dennis Groß (he/him) • Edited

I second webpack alias. I also suggest using an expressive prefix for the alias so everyone in the team understands that the import uses an alias.

But Nilanth made a good job explaining why some sort of absolute imports makes your life easier.

Some comments have been hidden by the post's author - find out more