Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions napi/angular-compiler/vite-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export interface PluginOptions {
* ```
*/
angularVersion?: AngularVersion

/** Optional callback to transform template content before compilation. Applied during both initial build and HMR. */
templateTransform?: (content: string, filePath: string) => string
}

// Match all TypeScript files - we'll filter by @Component/@Directive decorator in the handler
Expand Down Expand Up @@ -160,6 +163,9 @@ export function angular(options: PluginOptions = {}): Plugin[] {
if (!content) {
try {
content = await readFile(templatePath, 'utf-8')
if (options.templateTransform) {
content = options.templateTransform(content, templatePath)
}
resourceCache.set(templatePath, content)
} catch {
console.warn(`Failed to read template: ${templatePath}`)
Expand Down Expand Up @@ -368,6 +374,9 @@ export function angular(options: PluginOptions = {}): Plugin[] {
if (templateUrls.length > 0) {
const templatePath = resolve(dir, templateUrls[0])
templateContent = await readFile(templatePath, 'utf-8')
if (options.templateTransform) {
templateContent = options.templateTransform(templateContent, templatePath)
}
} else {
templateContent = extractInlineTemplate(source)
}
Expand Down
Loading