Open maxpatiiuk opened 5 months ago
Hey @maxpatiiuk, thanks for writing up the feature request!
I'm just curious, what is it that you're trying to do via your rollup plugin that you're unable to do? Just to get a sense of what the use-case for this is for your team.
Sure. We have several use cases that would be much easier to resolve with a TypeScript transformer (until Stencil supports all of this natively):
extends
in our components adds a lot of boilerplate to each component. Our solution at the moment was something like https://github.com/ionic-team/stencil/issues/3162 (we added Lit-compatible controllers to Stencil, that can hook into the component lifecycle)@Watch
ers support (adding watchers on the fly at runtime) to watch changes for props that are common between many componentsIn general, most things are motivated by:
Thanks for providing that breakdown! I know that code re-use and extensibility / composition is a pain point in Stencil at present and it is something that we want to address for sure.
I'm going to circulate what you shared among the team and we'll noodle on it a bit!
Prerequisites
Describe the Feature Request
We need an ability to provide a custom TypeScript transformer plugin to Stencil to modify the code BEFORE Stencil extracts data from the AST.
https://github.com/ionic-team/stencil/blob/962372f3d2ceb1c25573b845ee34d2ccb40945ff/src/compiler/transpile/transpile-module.ts#L114-L122
Describe the Use Case
Stencil allows to define a rollup plugin that would transform the output code.
However, current implementation is very limited because rollup plugins are called after Stencil pulled the data from the AST for each component and transformed the code using TypeScript plugins.
This means:
@Watch
/@State
/@Prop
/@Method
/@Listen
either, as the component meta is extracted by Stencil at an earlier step, before the Rollup plugin is run.BUILD
object (that is used by Stencil for dead code elimination in minified production builds) is computed at an earlier step.Describe Preferred Solution
Ability to provide a custom TypeScript transformer in the
stencil.config.ts
file that would be called before Stencil extracts data from the AST and begins it's transformation.Describe Alternatives
Expose
buildCtx
andcompilerCtx
objects to Rollup plugins so that they could modify the Stencil's compiler meta or internal file system before Stencil outputs the built files.A partial solution may also be to expose the
cmpMeta
to the component at run-time to let it dynamically define watchers and to let it get a list of all the props/states available on the component (to integrate each prop with an external reactivity library)Without this, our "hacky" solution may be to use Stencil's Core Compiler API rather than the CLI directly (we would have to create our own CLI) to provide a custom file system object that would modify the source files before Stencil extracts component meta from the AST
Related Code
No response
Additional Information
Requested by: Esri
Related issues: