link-module-alias icon indicating copy to clipboard operation
link-module-alias copied to clipboard

The best way to use this module fixing "@" and "deep" issue

Open Yehonal opened this issue 4 years ago • 2 comments

Before using this package I was reading this article: https://gist.github.com/branneman/8048520 and then I came up with my "npm link solution": https://gist.github.com/branneman/8048520#gistcomment-3346781

But I've noticed that link-module-alias uses more or less the same approach and I managed to find a proper way to use it in every cases.

First of all stop to create tons of useless aliases, do it in the right way and create an alias that has exactly the same name of your package. In this way if you are using your package as a "final application" or as a dependency, the paths will be kept in both cases.

Second, do not use the "postinstall" script but the "prepare" script in this way: "prepare": "npx link-module-alias"

It will create the link only when you're running npm install inside the package folder (so won't do anything when your package is included as a dependency).

When your package is a dependency nodejs will resolve the paths automatically without the need of a symlink.

PLUS: if you still have issues with intellisense on your vscode, consider to add the "paths" option inside tsconfig.json that will point to your root directory.

I'm trying it in production and everything works fine

Yehonal avatar Jun 19 '20 10:06 Yehonal

First of all stop to create tons of useless aliases, do it in the right way and create an alias that has exactly the same name of your package. In this way if you are using your package as a "final application" or as a dependency, the paths will be kept in both cases.

This is very opinionated and I find myself giving aliases to folders I want to hide their long path, going with "same structure" is very limiting.

mrsufgi avatar Jul 01 '20 14:07 mrsufgi

I think that the first goal of an alias module should be the possibility to solve the "relative paths hell"

About the long paths, personally I use a domain based folder structure under /src that most of the time doesn't exceed the 2 levels

Yehonal avatar Jul 02 '20 06:07 Yehonal