File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed
packages/angular/build/src/tools/vite Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import type { Connect } from 'vite' ;
9+ import type { Connect , ViteDevServer } from 'vite' ;
10+ import { pathnameWithoutBasePath } from '../utils' ;
1011
1112const ANGULAR_COMPONENT_PREFIX = '/@ng/component' ;
1213
1314export function createAngularComponentMiddleware (
15+ server : ViteDevServer ,
1416 templateUpdates : ReadonlyMap < string , string > ,
1517) : Connect . NextHandleFunction {
1618 return function angularComponentMiddleware ( req , res , next ) {
1719 if ( req . url === undefined || res . writableEnded ) {
1820 return ;
1921 }
2022
21- if ( ! req . url . startsWith ( ANGULAR_COMPONENT_PREFIX ) ) {
23+ const pathname = pathnameWithoutBasePath ( req . url , server . config . base ) ;
24+ if ( ! pathname . includes ( ANGULAR_COMPONENT_PREFIX ) ) {
2225 next ( ) ;
2326
2427 return ;
Original file line number Diff line number Diff line change @@ -46,8 +46,11 @@ export async function createAngularMemoryPlugin(
4646 // Vite will resolve these these files example:
4747 // `file:///@ng/component?c=src%2Fapp%2Fapp.component.ts%40AppComponent&t=1737017253850`
4848 const sourcePath = fileURLToPath ( source ) ;
49- const { root } = parse ( sourcePath ) ;
50- const sourceWithoutRoot = normalizePath ( '/' + sourcePath . slice ( root . length ) ) ;
49+ const sourceWithoutRoot = sourcePath . startsWith ( virtualProjectRoot )
50+ ? normalizePath ( '/' + relative ( virtualProjectRoot , sourcePath ) )
51+ : // TODO: remove once https://github.com/angular/angular/blob/4e6017a9f5cda389c5fbf4f2c1519ce1bba23e11/packages/compiler/src/render3/r3_hmr_compiler.ts#L57
52+ // is changed from `/@ng` to `./@ng/`
53+ normalizePath ( '/' + sourcePath . slice ( parse ( sourcePath ) . root . length ) ) ;
5154
5255 if ( sourceWithoutRoot . startsWith ( ANGULAR_PREFIX ) ) {
5356 const [ , query ] = source . split ( '?' , 2 ) ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ export function createAngularSetupMiddlewaresPlugin(
8888
8989 // Headers, assets and resources get handled first
9090 server . middlewares . use ( createAngularHeadersMiddleware ( server ) ) ;
91- server . middlewares . use ( createAngularComponentMiddleware ( templateUpdates ) ) ;
91+ server . middlewares . use ( createAngularComponentMiddleware ( server , templateUpdates ) ) ;
9292 server . middlewares . use (
9393 createAngularAssetsMiddleware (
9494 server ,
You can’t perform that action at this time.
0 commit comments