Skip to content

feat(vite): add templateTransform hook for template preprocessing#150

Merged
Boshen merged 1 commit intovoidzero-dev:mainfrom
BenjaminDobler:feat/template-transform-hook
Mar 18, 2026
Merged

feat(vite): add templateTransform hook for template preprocessing#150
Boshen merged 1 commit intovoidzero-dev:mainfrom
BenjaminDobler:feat/template-transform-hook

Conversation

@BenjaminDobler
Copy link
Contributor

Summary

  • Adds an optional templateTransform callback to PluginOptions that transforms template content after reading from disk but before compilation
  • Applied in both resolveResources() (initial build) and the HMR recompilation endpoint, so behavior stays consistent
  • Non-breaking: the callback is optional and defaults to no-op

Closes #149

Usage

angular({
  templateTransform: (content, filePath) => {
    // Add data-testid attributes, inject source location metadata, etc.
    return transformedContent
  },
})

Test plan

  • Verify external templates are transformed during initial compilation
  • Verify HMR updates apply the same transform to fresh template content
  • Verify behavior is unchanged when templateTransform is not provided

Happy to add tests if desired — the change is minimal (~6 lines of logic) and the repo doesn't currently have plugin-level unit tests.

🤖 Generated with Claude Code

Add an optional `templateTransform` callback to the plugin options,
allowing external tools to transform Angular template content before
compilation while preserving the full HMR pipeline.

Closes voidzero-dev#149

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Boshen Boshen merged commit e698f76 into voidzero-dev:main Mar 18, 2026
2 checks passed
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.

Feature: templateTransform hook in Vite plugin for template preprocessing

3 participants