@@ -3,7 +3,7 @@ import { logger } from "@/utils/logger.js";
33import { measureTime } from "@/utils/time-perf.js" ;
44import fse from "fs-extra" ;
55import kleur from "kleur" ;
6- import { join , resolve } from "pathe" ;
6+ import { join } from "pathe" ;
77import { Fragment , h } from "preact" ;
88import { renderToStringAsync } from "preact-render-to-string" ;
99import type {
@@ -20,6 +20,8 @@ import {
2020 OUTPUT_BUNDLE_BROWSER_DIR ,
2121 OUTPUT_BUNDLE_SERVER_DIR ,
2222 OUTPUT_PRANX_DIR ,
23+ SERVER_MANIFEST_OUTPUT_PATH ,
24+ SITE_MANIFEST_OUTPUT_PATH ,
2325} from "../build/constants.js" ;
2426import { generate_html_template } from "../build/generate_html_template.js" ;
2527
@@ -38,14 +40,14 @@ export async function build() {
3840 optimize : true ,
3941 } ) ;
4042
41- const site_manifest : SERVER_MANIFEST = {
43+ const server_site_manifest : SERVER_MANIFEST = {
4244 entry_server : join ( OUTPUT_BUNDLE_SERVER_DIR , "entry-server.js" ) ,
4345 routes : [ ] ,
4446 } ;
4547
4648 let server_entry_module : ServerEntryModule | null = null ;
4749
48- server_entry_module = ( await import ( site_manifest . entry_server ) ) as ServerEntryModule ;
50+ server_entry_module = ( await import ( server_site_manifest . entry_server ) ) as ServerEntryModule ;
4951
5052 const pranx_bundle_replace_path = join ( ".pranx" , "browser" ) ;
5153
@@ -56,6 +58,7 @@ export async function build() {
5658 entry : "" ,
5759 } ;
5860
61+ // Calculating css files
5962 for ( const [ file , _output ] of Object . entries ( browser_bundle_metafile . metafile . outputs ) ) {
6063 if ( file . endsWith ( "entry-client.css" ) ) {
6164 css_output . entry = file . replace ( pranx_bundle_replace_path , "" ) ;
@@ -73,6 +76,7 @@ export async function build() {
7376 }
7477 }
7578
79+ // Generating Manifest and generating static pages
7680 for ( const [ file , _output ] of Object . entries ( browser_bundle_metafile . metafile . outputs ) ) {
7781 if ( ! file . endsWith ( "page.js" ) ) continue ;
7882
@@ -132,7 +136,7 @@ path: ${final_path}`);
132136 const static_paths_result = await getStaticPaths ( ) ;
133137 const new_final_path = final_path ;
134138
135- site_manifest . routes . push ( {
139+ server_site_manifest . routes . push ( {
136140 path : final_path ,
137141 module : pages_relative_path ,
138142 props : statics_fn_result . props ,
@@ -142,6 +146,7 @@ path: ${final_path}`);
142146 dynamic_params : dynamic_params ,
143147 css : [ css_output . entry , css_output [ final_path ] || "" ] . filter ( Boolean ) ,
144148 static_generated_routes : [ ] ,
149+ absolute_module_path : module_path ,
145150 } ) ;
146151
147152 for ( const static_path of static_paths_result . paths ) {
@@ -172,7 +177,7 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
172177 } ) ;
173178 }
174179
175- site_manifest . routes . at ( - 1 ) ?. static_generated_routes . push ( {
180+ server_site_manifest . routes . at ( - 1 ) ?. static_generated_routes . push ( {
176181 path : replaced_path ,
177182 props : statics_fn_result . props || { } ,
178183 revalidate : statics_fn_result . revalidate || - 1 ,
@@ -187,7 +192,7 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
187192 } ) ;
188193 }
189194
190- site_manifest . routes . push ( {
195+ server_site_manifest . routes . push ( {
191196 path : final_path ,
192197 module : pages_relative_path ,
193198 props : statics_fn_result . props ,
@@ -197,11 +202,12 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
197202 is_dynamic : isUrlDynamic ,
198203 dynamic_params : dynamic_params ,
199204 css : [ css_output . entry , css_output [ final_path ] || "" ] . filter ( Boolean ) as string [ ] ,
205+ absolute_module_path : module_path ,
200206 } ) ;
201207 }
202208
203209 const hydrate_data : HYDRATE_DATA = {
204- routes : site_manifest . routes . map ( ( r ) => {
210+ routes : server_site_manifest . routes . map ( ( r ) => {
205211 return {
206212 module : r . module ,
207213 path : r . path ,
@@ -222,11 +228,11 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
222228
223229 const hydrate_data_as_string = JSON . stringify ( hydrate_data ) ;
224230
225- for ( const route of site_manifest . routes ) {
231+ // Writing static files and prerender pages
232+ for ( const route of server_site_manifest . routes ) {
226233 if ( route . rendering_kind === "server-side" ) continue ;
227234
228- const file_absolute = resolve ( join ( OUTPUT_BUNDLE_SERVER_DIR , "pages" , route . module ) ) ;
229- const page_module = ( await import ( file_absolute ) ) as PageModule ;
235+ const page_module = ( await import ( route . absolute_module_path ) ) as PageModule ;
230236
231237 if ( route . static_generated_routes . length > 0 ) {
232238 for ( const static_route of route . static_generated_routes ) {
@@ -272,19 +278,12 @@ params returned by getStaticPaths: ${JSON.stringify(static_path.params)}`);
272278 await fse . writeFile ( output_html_path , html ) ;
273279 }
274280
275- await fse . writeFile (
276- join ( OUTPUT_BUNDLE_SERVER_DIR , "server.manifest.json" ) ,
277- JSON . stringify ( site_manifest )
278- ) ;
279-
280- await fse . writeFile (
281- join ( OUTPUT_BUNDLE_BROWSER_DIR , "site.manifest.json" ) ,
282- JSON . stringify ( hydrate_data )
283- ) ;
281+ await fse . writeFile ( SERVER_MANIFEST_OUTPUT_PATH , JSON . stringify ( server_site_manifest ) ) ;
282+ await fse . writeFile ( SITE_MANIFEST_OUTPUT_PATH , JSON . stringify ( hydrate_data ) ) ;
284283
285284 const BUILD_TIME = measureTime ( "build_measure_time" ) ;
286285
287- printRoutesTreeForUser ( site_manifest . routes ) ;
286+ printRoutesTreeForUser ( server_site_manifest . routes ) ;
288287
289288 logger . success ( `Project builded in ${ BUILD_TIME } ms\n` ) ;
290289}
0 commit comments