@@ -28,10 +28,12 @@ const supportedPlatforms: Record<BuildPlatform, string> = {
28
28
29
29
/**
30
30
* Build the app into a worker for serverless platform. Functions include:
31
- * - import routes modules (since deno deploy/clouflare don't support dynamic import)
31
+ * - import routes modules (since deno-deploy/cloudflare don't support dynamic import)
32
+ * - apply module loaders
33
+ * - pre-compile/bundle client modules
32
34
* - resolve import maps
33
- * - pre-compile client modules
34
- * - bundle client modules
35
+ *
36
+ * after build, you need to bootstrap the server from `./dist/server.js`
35
37
*/
36
38
export async function build ( serverEntry ?: string ) {
37
39
const workingDir = Deno . cwd ( ) ;
@@ -276,7 +278,7 @@ export async function build(serverEntry?: string) {
276
278
tasks . push ( `${ alephPkgUri } /framework/core/nomodule.ts` ) ;
277
279
278
280
const entryModules = new Map ( tasks . map ( ( task ) => [ task , 0 ] ) ) ;
279
- const tracing = new Set < string > ( ) ;
281
+ const allClientModules = new Set < string > ( ) ;
280
282
281
283
// transform client modules
282
284
const serverHandler : FetchHandler | undefined = Reflect . get ( globalThis , "__ALEPH_SERVER" ) ?. handler ;
@@ -313,14 +315,16 @@ export async function build(serverEntry?: string) {
313
315
} else if ( url . searchParams . has ( "module" ) ) {
314
316
deps . add ( `${ alephPkgUri } /framework/core/style.ts` ) ;
315
317
}
316
- tracing . add ( specifier ) ;
318
+ allClientModules . add ( specifier ) ;
317
319
} ) ) ;
318
- tasks = Array . from ( deps ) . filter ( ( specifier ) => ! tracing . has ( specifier ) ) ;
320
+ tasks = Array . from ( deps ) . filter ( ( specifier ) => ! allClientModules . has ( specifier ) ) ;
319
321
}
320
322
}
321
323
322
- // count client module refs
324
+ const clientModules = new Map ( entryModules ) ;
323
325
const refs = new Map < string , Set < string > > ( ) ;
326
+
327
+ // count client module refs
324
328
for ( const [ name ] of entryModules ) {
325
329
clientDependencyGraph ?. walk ( name , ( { specifier } , importer ) => {
326
330
if ( importer ) {
@@ -334,8 +338,6 @@ export async function build(serverEntry?: string) {
334
338
} ) ;
335
339
}
336
340
337
- const clientModules = new Map ( entryModules ) ;
338
-
339
341
// find shared modules
340
342
for ( const [ specifier , counter ] of refs ) {
341
343
if ( counter . size > 1 ) {
@@ -428,6 +430,7 @@ export async function build(serverEntry?: string) {
428
430
) ;
429
431
430
432
// clean up then exit
433
+ // todo: remove dead client modules
431
434
if ( jsxShimFile ) {
432
435
await Deno . remove ( jsxShimFile ) ;
433
436
}
0 commit comments