You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a developer using Module federation I want to be able to use TypeScript alias paths in my remote application so that I'm able to benefit from all of the things that come with alias paths in TypeScript like improved readability, simplified refactoring and in general a better developer experience.
I have projects using module federation for a long time. We have implemented a workaround for providing type support by generating type definitions and publishing them to npm. Later published type definitions are used in module federation consumer apps. These projects are using TypeScript alias paths and so far we haven't had a problem with that. We already migrated to Module federation 2.0 and now we are in a process of replacing the mentioned workaround with dts. Unfortunatelly, TypeScript alias paths are preventing us from moving forward.
Suggested solution
I looked into @module-federation/dts-plugin and I found out that a temporaty tsconfig file is being created based on a original tsconfig from the project before running tsc or vue-tsc for generating type declarations. I also see that only paths and baseUrl properties are being ignored from compilerOptions (here is a permalink). Then I found a comment mentioning that TypeScript compiler doesn't replace aliases, which is very much true.
There is an open source library tsc-alias that can replace alias paths with relative paths after typescript compilation. If you keep the existing alias path configuration from the original tsconfig and run tsc-alias -p path/to/temporary/tsconfig.json then it should replace aliases.
Alternative
No response
Additional context
I'm ready to contribute by opening a PR. I'm just not sure where tsc-alias should live. Right now tsc is used through npx, this means it is installed on a consumer side and it sounds reasonable to me. Should I assume that if alias paths are being configured in tsconfig consumer app has tsc-alias installed as well? So, I can use npx tsc-alias the same way.
Clear and concise description of the problem
As a developer using Module federation I want to be able to use TypeScript alias paths in my remote application so that I'm able to benefit from all of the things that come with alias paths in TypeScript like improved readability, simplified refactoring and in general a better developer experience.
I have projects using module federation for a long time. We have implemented a workaround for providing type support by generating type definitions and publishing them to npm. Later published type definitions are used in module federation consumer apps. These projects are using TypeScript alias paths and so far we haven't had a problem with that. We already migrated to Module federation 2.0 and now we are in a process of replacing the mentioned workaround with
dts
. Unfortunatelly, TypeScript alias paths are preventing us from moving forward.Suggested solution
I looked into
@module-federation/dts-plugin
and I found out that a temporaty tsconfig file is being created based on a original tsconfig from the project before runningtsc
orvue-tsc
for generating type declarations. I also see that onlypaths
andbaseUrl
properties are being ignored fromcompilerOptions
(here is a permalink). Then I found a comment mentioning that TypeScript compiler doesn't replace aliases, which is very much true.There is an open source library tsc-alias that can replace alias paths with relative paths after typescript compilation. If you keep the existing alias path configuration from the original tsconfig and run
tsc-alias -p path/to/temporary/tsconfig.json
then it should replace aliases.Alternative
No response
Additional context
I'm ready to contribute by opening a PR. I'm just not sure where
tsc-alias
should live. Right nowtsc
is used throughnpx
, this means it is installed on a consumer side and it sounds reasonable to me. Should I assume that if alias paths are being configured in tsconfig consumer app hastsc-alias
installed as well? So, I can usenpx tsc-alias
the same way.Validations
The text was updated successfully, but these errors were encountered: