File tree 3 files changed +11
-5
lines changed
packages/angular/build/src/tools/vite
3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change 6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import type { Connect } from 'vite' ;
9
+ import type { Connect , ViteDevServer } from 'vite' ;
10
+ import { pathnameWithoutBasePath } from '../utils' ;
10
11
11
12
const ANGULAR_COMPONENT_PREFIX = '/@ng/component' ;
12
13
13
14
export function createAngularComponentMiddleware (
15
+ server : ViteDevServer ,
14
16
templateUpdates : ReadonlyMap < string , string > ,
15
17
) : Connect . NextHandleFunction {
16
18
return function angularComponentMiddleware ( req , res , next ) {
17
19
if ( req . url === undefined || res . writableEnded ) {
18
20
return ;
19
21
}
20
22
21
- if ( ! req . url . startsWith ( ANGULAR_COMPONENT_PREFIX ) ) {
23
+ const pathname = pathnameWithoutBasePath ( req . url , server . config . base ) ;
24
+ if ( ! pathname . includes ( ANGULAR_COMPONENT_PREFIX ) ) {
22
25
next ( ) ;
23
26
24
27
return ;
Original file line number Diff line number Diff line change @@ -46,8 +46,11 @@ export async function createAngularMemoryPlugin(
46
46
// Vite will resolve these these files example:
47
47
// `file:///@ng/component?c=src%2Fapp%2Fapp.component.ts%40AppComponent&t=1737017253850`
48
48
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 ) ) ;
51
54
52
55
if ( sourceWithoutRoot . startsWith ( ANGULAR_PREFIX ) ) {
53
56
const [ , query ] = source . split ( '?' , 2 ) ;
Original file line number Diff line number Diff line change @@ -88,7 +88,7 @@ export function createAngularSetupMiddlewaresPlugin(
88
88
89
89
// Headers, assets and resources get handled first
90
90
server . middlewares . use ( createAngularHeadersMiddleware ( server ) ) ;
91
- server . middlewares . use ( createAngularComponentMiddleware ( templateUpdates ) ) ;
91
+ server . middlewares . use ( createAngularComponentMiddleware ( server , templateUpdates ) ) ;
92
92
server . middlewares . use (
93
93
createAngularAssetsMiddleware (
94
94
server ,
You can’t perform that action at this time.
0 commit comments