feat: Allow to specify in CustomOuputTarget if the output have to be re-executed on each build
Prerequisites
- [X] I have read the Contributing Guidelines.
- [X] I agree to follow the Code of Conduct.
- [X] I have searched for existing issues that already include this feature request, without success.
Describe the Feature Request
I'd like to have a parameter that lets you choose whether the custom output target can be called at every change or only during the "final" build.
Describe the Use Case
I've created a little plugin to retrieve all @config docsTags in a component-config.d.ts so it's easyer to customise the default state of a component.
stencil.config.ts
export const config: Config = {
... // Config
outputTargets: [
{
type: 'custom',
name: 'component-option',
execType: 'run', // new prop in CustomOutputTarget
async generator(config, compilerCtx: any, buildCtx, docs): Promise<void> {
// Logique to create a .d.ts file
}
},
]
}
component-config.d.ts
export interface ComponentOptions {
"pop-drawer"?: {
triggerAction?: "click" | "context-menu" | "hover";
side?: "end" | "start";
open?: boolean;
}
}
These options are extracted from the component, but if a modification is made to this component, the output target is not updated.
Describe Preferred Solution
export const config: Config = {
... // Config
outputTargets: [
{
type: 'custom',
name: 'component-option',
execType: 'run' | 'build', // new prop in CustomOutputTarget
async generator(config, compilerCtx: any, buildCtx, docs): Promise<void> { }
},
]
}
// 'run' : run on every change
// 'build' : run only on "final" build
Describe Alternatives
No response
Related Code
https://github.com/Sukaato/stencil-custom-target-example
Additional Information
No response
I'd like to have a parameter that lets you choose whether the custom output target can be called at every change or only during the "final" build.
Can you elaborate on this? When you say "at every change" are you talking about having the output target run during watch mode? Because this works for me given your example project. I guess, could you explain in detail what the current behavior is and your expected/desired behavior?
Yes when a mean at every change, i mean in dev mode.
Like i said, when i add or remove a @config in JSdoc, the component-config.d.ts is not updated (not the components.d.ts that stencil provide),
I add some console.log in my component-config.target.ts but there only called on final build, not in dev mode.
Gotcha, what I can observe is that the src/components.d.ts is changing after every save:
However it seems that VSCode is not picking this up:
I will ingest this into our backlog for the team to take a closer look at. Any contributions are welcome!
After running a few tests, I realized that the custom output target is never called when the --dev flag is set in the CLI, when it is cleared, the output target is called on first compilation, and on rebuild.
Based on this result, I think the bug is related to the dev flag.
This was closed in #5541, and that fix will be released today!
The fix for this issue has been released as a part of today's Stencil v4.18.1 release!