typescript - How to use paths in tsconfig.json -
i reading path-mapping in tsconfig.json
, wanted use avoid using following ugly paths:
the project organization bit weird because have mono-repository contains projects , libraries. projects grouped company , browser / server / universal.
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
Post a Comment