typescript - How to use paths in tsconfig.json -


i reading path-mapping in tsconfig.json , wanted use avoid using following ugly paths:

enter image description here

the project organization bit weird because have mono-repository contains projects , libraries. projects grouped company , browser / server / universal.

enter image description here

how can configure paths in tsconfig.json instead of:

import { } "../../../../../lib/src/[browser/server/universal]/...";

i can use:

import { } "lib/src/[browser/server/universal]/...";

will else required in webpack config? or tsconfig.json enough?

this can set on tsconfig.json file, ts feature.

you can this:

"compileroptions": {         "baseurl": "src", // must specified if "paths" is.          ...         "paths": {             "@app/*": ["app/*"],             "@config/*": ["app/_config/*"],             "@environment/*": ["environments/*"],             "@shared/*": ["app/_shared/*"],             "@helpers/*": ["helpers/*"]         },         ... 

have in mind path want refer to, takes baseurl base of route pointing , it's mandatory described on doc.

the character '@' not mandatory.

after set on way, can use this:

import { yo } '@config/index'; 

the thing might notice intellisense not work in current latest version, suggest follow index convention importing/exporting files.

https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -