-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler option to rewrite import file paths #35351
Comments
I have been experimenting with webpack and rollup with no success. I have a minimal example repo, which features a branch where I attempt to solve the problem with webpack: https://github.com/alshdavid-sandbox/typescript-library |
Not likely to happen: |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
I ran into this issue today while developing a component library using TypeScript and had good results using the package tsc-alias to fix my imports after compilation. |
Problem
When using paths to apply an alias to an import, the files do not represent the expected target path.
Not rewriting the paths is the correct and expected behaviour from the TypeScript compiler and further rewriting belongs to extra tooling layers, like Webpack.
Webpack can be used to rewrite the paths in the emitted javascript bundles, however this rewrite is not represented in declaration files or maps so its behaviour is incomplete. This means that modules which are expected to have consumable declarations are unable to rely on the generated files.
Proposal
It would be awesome if TypeScript included the ability to alias + rewrite imports which worked on both emitted
.js
,.d.ts
files and source maps.Perhaps the inclusion of a new compiler option called something similar to
rewriteImports
is a solution.Below I am setting
~
as a path which represents an absolute import path from the root of the source directory.Example
Given the following folder structure:
Imagine that
a/index.ts
looks like:The output javascript and declaration files would look like:
The text was updated successfully, but these errors were encountered: