3

In TypeScript, what is the right way to reference the current file and directory, like __filename and __dirname in Node.js, that would work when compiling for the client-side?


I'm currently working on an Angular.js 4 project, implementing components that provide their own sub-routing, which is too verbose and error-prone for the clients to reference directly, so I want those components to be able to generate proper routing override by themselves, which in turn requires that each such component knows its file name and the relative directory where it sits.

vitaly-t
  • 24,279
  • 15
  • 116
  • 138
  • Please, explain further, are you trying to generate route paths from filesystem relative paths? It's not possible. Could be XY problem. – Estus Flask Nov 11 '17 at 19:12
  • @estus I was hoping to avoid writing things like `loadChildren: './my-component/my-component.module.ts#'` inside the main root, and have instead the component inject such things automatically where needed, if it is at all possible. – vitaly-t Nov 12 '17 at 02:45
  • It's possible to shorten paths for `import` with Typescript `paths` config. But no, not for the things you're asking about. Could be possibly addressed with Webpack config, https://stackoverflow.com/questions/25553868/current-file-path-in-webpack – Estus Flask Nov 12 '17 at 10:54

0 Answers0