Skip to content

Conversation

@bashmish
Copy link
Member

What I did

  1. Add 2nd param to "plugin.api.addHtmlTransformer" to specify the stage of the transform - "input" or "output"
  2. By default keep it "output" as before, for backwards compatibility
  3. When "input" is set, it will apply to the input HTML instead of output HTML, allowing to add assets and stuff like that that later will go through the pipeline

GOOD TO MENTION: Do not confuse with Vite's "order", their transforms always apply to the HTML before it goes through the pipeline, and the "order" only defines the priority of transform functions. If we need to add smth like this in the future, we gonna use a 3rd param, e.g. "priority", for that, but this PR has nothing to do with that, just my 2 cents.

@changeset-bot
Copy link

changeset-bot bot commented Nov 26, 2025

🦋 Changeset detected

Latest commit: 44fff34

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@web/rollup-plugin-html Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

// run transform functions on input HTML
const inputTransforms = [...(inputExternalTransformHtmlFns ?? [])];
for (const transform of inputTransforms) {
inputHtml = await transform(inputHtml, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add some error handling here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good one, in general the exception will be associated with a particular plugin, so locating the problem should be easy enough, but it can be improved always but making it more specific, just maybe logical not to mix up here with this change since the behavior mimics that of the output html transform
or do you want to do it in this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think even just a nice readable error message "transform hook threw an error" or something would be fine, can indeed improve in the future.

(not for this PR, but) Typically when I implement plugin systems in my tooling I require them to have a name, e.g.:

const fooPlugin = {
  name: 'foo-plugin',
  someHook: () => {}
}

That way you can throw really helpful error messages that include the name of the plugin it threw on

@bashmish bashmish merged commit 5e7cd98 into master Nov 26, 2025
7 of 9 checks passed
@bashmish bashmish deleted the feat/transform-input-html branch November 26, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants