TypeScript Import Path Alias

后端 未结 2 690
情书的邮戳
情书的邮戳 2020-11-28 06:40

I am currently working on a TypeScript application which is comprised of multiple Node modules written in TypeScript, that are installed into the node_modules d

2条回答
  •  清歌不尽
    2020-11-28 06:50

    If you are using paths, you will need to change back absolute paths to relative paths for it to work after compiling typescript into plain javascript using tsc.

    Most popular solution for this has been tsconfig-paths so far.

    I've tried it, but it did not work for me for my complicated setup. Also, it resolves paths in run-time, meaning overhead in terms of your package size and resolve performance.

    So, I wrote a solution myself, tscpaths.

    I'd say it's better overall because it replaces paths at compile-time. It means there is no runtime dependency or any performance overhead. It's pretty simple to use. You just need to add a line to your build scripts in package.json.

    The project is pretty young, so there could be some issues if your setup is very complicated. It works flawlessly for my setup, though my setup is fairly complex.

提交回复
热议问题