Compiling typescript path aliases to relative path

2019-07-13 03:51发布

问题:

I have a typescript project that uses paths for imports. For example:

"paths": {
  "@example/*": ["./src/*"], 
}

Thus the project can import files directly from using statement like:

import { foo } from "@example/boo/foo";

For publishing to NPM I have I'm compiling the typescript files and then copying the result to a dist folder. Thus all the *.d.ts and corresponding *.js files are in the dist folder. I also copy package.json to the dist folder.

I now test this by generation a new typescript project and then run npm i -S ../example/dist, in order to install the project and attempt to run some of the compiled typescript code.

However the relative imports no longer work. For example if boo.ts depends on foo.ts it will say that it can't resolve foo.ts.

When I look at the *.d.ts files they contain the same paths that were used the source code before it was compiled. Is it possible to turn these into relative paths?

Update

I looks as if generating relative paths for Node is something Typescript does not perform automatically. If you would like this feature, as I would, please provide feedback on this bug report.