stencil icon indicating copy to clipboard operation
stencil copied to clipboard

feat: Allow to specify in CustomOuputTarget if the output have to be re-executed on each build

Open Sukaato opened this issue 2 years ago • 4 comments

Prerequisites

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

Sukaato avatar Mar 18 '24 18:03 Sukaato

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?

christian-bromann avatar Mar 18 '24 22:03 christian-bromann

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.

Sukaato avatar Mar 19 '24 09:03 Sukaato

Gotcha, what I can observe is that the src/components.d.ts is changing after every save:

drawer

However it seems that VSCode is not picking this up: Screenshot 2024-03-19 at 2 56 44 PM

I will ingest this into our backlog for the team to take a closer look at. Any contributions are welcome!

christian-bromann avatar Mar 19 '24 21:03 christian-bromann

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.

Sukaato avatar Mar 20 '24 09:03 Sukaato

This was closed in #5541, and that fix will be released today!

alicewriteswrongs avatar May 13 '24 15:05 alicewriteswrongs

The fix for this issue has been released as a part of today's Stencil v4.18.1 release!

alicewriteswrongs avatar May 13 '24 19:05 alicewriteswrongs