Home > OS >  how to replace the typescript alias when compile
how to replace the typescript alias when compile

Time:02-12

I define the typescript alias in tsconfig.json like this:

"paths": {
      "@net/*":["net/*"],
      "@auth/*":["auth/*"],
    },

then using this alias in index.ts like this:

import { ResponseHandler } from "@net/rest/ResponseHandler";
export { ResponseHandler };

when compile the typescript project, I want to replace the alias @net to the project real path like this ../net/rest/ResponseHandler so that the project path could parse correctly when using in other project as a lib. how to replace the alias name? I have tried using tsc-alias by using this command after installed the tsc-alias lib:

"tscbuild": "tsc && tsc-alias",

but it did not replace the @net, what should I do to replace the typescript alias success? any suggestion?

CodePudding user response:

I do not know how to replace the path using tsc-alias. But you can tried to install ttypescript:

yarn add ttypescript --save-dev

and replace your tscbuild command like this:

"tscbuild": "ttsc",

I have tried and it could succesfully replace the path like @net to ../src/net/.

  • Related