feat(compiler): support paths in compiler options #1584
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Someone was asking about why path aliases in the
compilerOptions
section of tsconfig didn't work in Stencil, and I ended up trying to solve it.First, I created rollup-plugin-typescript-paths, which uses
nodeModuleNameResolver
from the typescript api to resolve imports using the path aliases (it returns the transpiled.js
counterpart of the.ts
file).Then I realized that I had an issue with const enums: Stencil removes the
paths
field from the compiler options entirely (intranspile-service.ts
), which causes the import statements of any const enums to remain in the file even though they have disappeared during transpilation (like interfaces).To solve this I decided to implement the resolving of path aliases in Stencil itself, because it's relatively simple and the only reason I wrote my plugin was for use with Stencil (though it should theoretically work in other contexts).
To try it out:
npm link
in stencilnpm init stencil app foobar
cd foobar
,npm link @stencil/core
BTW I tried writing a test but didn't have enough time to figure out how to change the compiler options within the test.