@@ -122,13 +122,26 @@ export class Project {
122
122
}
123
123
124
124
isHMRable ( moduleID : string ) {
125
- return ! reHttp . test ( moduleID ) && (
126
- moduleID === '/404.js' ||
127
- moduleID === '/app.js' ||
128
- moduleID . startsWith ( '/pages/' ) ||
129
- moduleID . startsWith ( '/components/' ) ||
130
- reStyleModuleExt . test ( moduleID )
131
- )
125
+ if ( reHttp . test ( moduleID ) ) {
126
+ return false
127
+ }
128
+ if ( reStyleModuleExt . test ( moduleID ) ) {
129
+ return true
130
+ }
131
+ if ( reModuleExt . test ( moduleID ) ) {
132
+ return moduleID === '/404.js' ||
133
+ moduleID === '/app.js' ||
134
+ moduleID . startsWith ( '/pages/' ) ||
135
+ moduleID . startsWith ( '/components/' )
136
+ }
137
+ if ( reMDExt . test ( moduleID ) ) {
138
+ return moduleID . startsWith ( '/pages/' )
139
+ }
140
+ const plugin = this . config . plugins . find ( p => p . test . test ( moduleID ) )
141
+ if ( plugin ?. acceptHMR ) {
142
+ return true
143
+ }
144
+ return false
132
145
}
133
146
134
147
isSSRable ( pathname : string ) : boolean {
@@ -555,6 +568,18 @@ export class Project {
555
568
await ensureDir ( this . buildDir )
556
569
}
557
570
571
+ // import postcss plugins
572
+ await Promise . all ( this . config . postcss . plugins . map ( async p => {
573
+ let name : string
574
+ if ( typeof p === 'string' ) {
575
+ name = p
576
+ } else {
577
+ name = p . name
578
+ }
579
+ const { default :
Plugin } = await import ( `https://esm.sh/${ name } [email protected] &no-check` )
580
+ this . #postcssPlugins[ name ] = Plugin
581
+ } ) )
582
+
558
583
// inject ALEPH global variable
559
584
Object . assign ( globalThis , {
560
585
ALEPH : {
@@ -571,18 +596,6 @@ export class Project {
571
596
// change current work dir to appDoot
572
597
Deno . chdir ( this . appRoot )
573
598
574
- // import postcss plugins
575
- await Promise . all ( this . config . postcss . plugins . map ( async p => {
576
- let name : string
577
- if ( typeof p === 'string' ) {
578
- name = p
579
- } else {
580
- name = p . name
581
- }
582
- const { default :
Plugin } = await import ( `https://esm.sh/${ name } [email protected] &no-check` )
583
- this . #postcssPlugins[ name ] = Plugin
584
- } ) )
585
-
586
599
for await ( const { path : p , } of walk ( this . srcDir , { ...walkOptions , maxDepth : 1 , exts : [ ...walkOptions . exts , '.jsx' , '.tsx' ] } ) ) {
587
600
const name = path . basename ( p )
588
601
switch ( name . replace ( reModuleExt , '' ) ) {
@@ -825,16 +838,16 @@ export class Project {
825
838
const metaFile = path . join ( this . buildDir , 'main.meta.json' )
826
839
827
840
module . jsContent = [
828
- this . isDev && 'import "./-/deno.land/x/aleph/hmr.js"; ' ,
829
- 'import "./-/deno.land/x/aleph/aleph.js"; ' ,
830
- 'import "./-/deno.land/x/aleph/context.js"; ' ,
831
- 'import "./-/deno.land/x/aleph/error.js"; ' ,
832
- 'import "./-/deno.land/x/aleph/events.js"; ' ,
833
- 'import "./-/deno.land/x/aleph/routing.js"; ' ,
834
- 'import "./-/deno.land/x/aleph/util.js"; ' ,
835
- 'import bootstrap from "./-/deno.land/x/aleph/bootstrap.js"; ' ,
836
- `bootstrap(${ JSON . stringify ( config , undefined , this . isDev ? 4 : undefined ) } ); `
837
- ] . filter ( Boolean ) . join ( this . isDev ? '\n' : '' )
841
+ this . isDev && 'import "./-/deno.land/x/aleph/hmr.js"' ,
842
+ 'import "./-/deno.land/x/aleph/aleph.js"' ,
843
+ 'import "./-/deno.land/x/aleph/context.js"' ,
844
+ 'import "./-/deno.land/x/aleph/error.js"' ,
845
+ 'import "./-/deno.land/x/aleph/events.js"' ,
846
+ 'import "./-/deno.land/x/aleph/routing.js"' ,
847
+ 'import "./-/deno.land/x/aleph/util.js"' ,
848
+ 'import bootstrap from "./-/deno.land/x/aleph/bootstrap.js"' ,
849
+ `bootstrap(${ JSON . stringify ( config , undefined , this . isDev ? 4 : undefined ) } )`
850
+ ] . filter ( Boolean ) . join ( this . isDev ? '\n' : '; ' )
838
851
module . hash = getHash ( module . jsContent )
839
852
module . jsFile = path . join ( this . buildDir , `main.${ module . hash . slice ( 0 , hashShort ) } .js` )
840
853
module . deps = [
@@ -1045,7 +1058,7 @@ export class Project {
1045
1058
] . filter ( Boolean ) . map ( l => ! this . isDev ? String ( l ) . trim ( ) : l ) . join ( this . isDev ? '\n' : '' )
1046
1059
mod . jsSourceMap = ''
1047
1060
mod . hash = getHash ( mod . jsContent )
1048
- } else if ( mod . loader === 'js' ) {
1061
+ } else if ( mod . loader === 'js' || mod . loader === 'ts' || mod . loader === 'jsx' || mod . loader === 'tsx' ) {
1049
1062
const useDenos : string [ ] = [ ]
1050
1063
const compileOptions = {
1051
1064
mode : this . mode ,
@@ -1291,22 +1304,6 @@ export class Project {
1291
1304
}
1292
1305
}
1293
1306
const ret : RenderResult = { url, status : url . pagePath === '' ? 404 : 200 , head : [ ] , scripts : [ ] , body : '<main></main>' , data : null }
1294
- Object . assign ( window , {
1295
- location : {
1296
- protocol : 'http:' ,
1297
- host : 'localhost' ,
1298
- hostname : 'localhost' ,
1299
- port : '' ,
1300
- href : 'https://localhost' + url . pathname + url . query . toString ( ) ,
1301
- origin : 'https://localhost' ,
1302
- pathname : url . pathname ,
1303
- search : url . query . toString ( ) ,
1304
- hash : '' ,
1305
- reload ( ) { } ,
1306
- replace ( ) { } ,
1307
- toString ( ) { return this . href } ,
1308
- }
1309
- } )
1310
1307
if ( ret . status === 404 ) {
1311
1308
if ( this . isDev ) {
1312
1309
log . warn ( `page '${ url . pathname } ' not found` )
@@ -1420,6 +1417,20 @@ export class Project {
1420
1417
// add virtual browser global objects
1421
1418
Object . assign ( globalThis , {
1422
1419
document : new Document ( ) ,
1420
+ location : {
1421
+ protocol : 'http:' ,
1422
+ host : 'localhost' ,
1423
+ hostname : 'localhost' ,
1424
+ port : '' ,
1425
+ href : 'https://localhost/' ,
1426
+ origin : 'https://localhost' ,
1427
+ pathname : '/' ,
1428
+ search : '' ,
1429
+ hash : '' ,
1430
+ reload ( ) { } ,
1431
+ replace ( ) { } ,
1432
+ toString ( ) { return this . href } ,
1433
+ } ,
1423
1434
innerWidth : 1920 ,
1424
1435
innerHeight : 1080 ,
1425
1436
devicePixelRatio : 1 ,
0 commit comments