Skip to content

Commit

Permalink
fix(vite-plugin-angular): resolve JIT external template/style files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonroberts authored Dec 11, 2024
1 parent defb6e4 commit 54e9488
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/vite-plugin-angular/src/lib/angular-vite-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CompilerHost, NgtscProgram } from '@angular/compiler-cli';
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';

import * as compilerCli from '@angular/compiler-cli';
import * as ts from 'typescript';
Expand Down Expand Up @@ -276,6 +276,16 @@ export function angular(options?: PluginOptions): Plugin[] {

return ctx.modules;
},
resolveId(id, importer) {
if (id.startsWith('angular:jit:')) {
const path = id.split(';')[1];
return `${normalizePath(
resolve(dirname(importer as string), path)
)}?raw`;
}

return id;
},
async transform(code, id) {
// Skip transforming node_modules
if (id.includes('node_modules')) {
Expand Down Expand Up @@ -311,14 +321,6 @@ export function angular(options?: PluginOptions): Plugin[] {
return;
}

/**
* Skip re-transforming files already JIT compiled
* with external styles or templates.
*/
if (jit && code.includes('angular:jit:')) {
return;
}

if (TS_EXT_REGEX.test(id)) {
if (id.includes('.ts?')) {
// Strip the query string off the ID
Expand Down

0 comments on commit 54e9488

Please sign in to comment.