@@ -31,12 +31,14 @@ interface Module {
3131interface Renderer {
3232 renderPage : Function
3333 renderHead : Function
34+ renderScripts : Function
3435}
3536
3637interface RenderResult {
3738 url : RouterURL
3839 status : number
3940 head : string [ ]
41+ scripts : Record < string , any > [ ]
4042 body : string
4143 data : Record < string , string > | null
4244}
@@ -52,7 +54,7 @@ export class Project {
5254 #routing: Routing = new Routing ( )
5355 #apiRouting: Routing = new Routing ( )
5456 #fsWatchListeners: Array < EventEmitter > = [ ]
55- #renderer: Renderer = { renderPage : ( ) => void 0 , renderHead : ( ) => void 0 }
57+ #renderer: Renderer = { renderPage : ( ) => void 0 , renderHead : ( ) => void 0 , renderScripts : ( ) => void 0 }
5658 #rendered: Map < string , Map < string , RenderResult > > = new Map ( )
5759 #postcssPlugins: Record < string , AcceptedPlugin > = { }
5860
@@ -76,7 +78,6 @@ export class Project {
7678 plugins : [ ] ,
7779 postcss : {
7880 plugins : [
79- 'postcss-flexbugs-fixes' ,
8081 'autoprefixer'
8182 ]
8283 }
@@ -238,14 +239,15 @@ export class Project {
238239
239240 const { baseUrl } = this . config
240241 const mainModule = this . #modules. get ( '/main.js' ) !
241- const { url, status, head, body, data } = await this . _renderPage ( loc )
242+ const { url, status, head, scripts , body, data } = await this . _renderPage ( loc )
242243 const html = createHtml ( {
243244 lang : url . locale ,
244245 head : head ,
245246 scripts : [
246247 data ? { type : 'application/json' , innerText : JSON . stringify ( data ) , id : 'ssr-data' } : '' ,
247248 { src : path . join ( baseUrl , `/_aleph/main.${ mainModule . hash . slice ( 0 , hashShort ) } .js` ) , type : 'module' } ,
248249 { src : path . join ( baseUrl , `/_aleph/-/deno.land/x/aleph/nomodule.js${ this . isDev ? '?dev' : '' } ` ) , nomodule : true } ,
250+ ...scripts
249251 ] ,
250252 body,
251253 minify : ! this . isDev
@@ -339,7 +341,7 @@ export class Project {
339341
340342 // write 404 page
341343 const { baseUrl } = this . config
342- const { url, head, body, data } = await this . _render404Page ( )
344+ const { url, head, scripts , body, data } = await this . _render404Page ( )
343345 const mainModule = this . #modules. get ( '/main.js' ) !
344346 const e404PageHtml = createHtml ( {
345347 lang : url . locale ,
@@ -348,6 +350,7 @@ export class Project {
348350 data ? { type : 'application/json' , innerText : JSON . stringify ( data ) , id : 'ssr-data' } : '' ,
349351 { src : path . join ( baseUrl , `/_aleph/main.${ mainModule . hash . slice ( 0 , hashShort ) } .js` ) , type : 'module' } ,
350352 { src : path . join ( baseUrl , `/_aleph/-/deno.land/x/aleph/nomodule.js${ this . isDev ? '?dev' : '' } ` ) , nomodule : true } ,
353+ ...scripts
351354 ] ,
352355 body,
353356 minify : ! this . isDev
@@ -521,7 +524,7 @@ export class Project {
521524 } else {
522525 name = p . name
523526 }
524- const { default : Plugin } = await import ( `https://esm.sh/${ name } ?external=postcss@8.1.3` )
527+ const { default : Plugin } = await import ( `https://esm.sh/${ name } ?external=postcss@8.1.3&no-check ` )
525528 this . #postcssPlugins[ name ] = Plugin
526529 } )
527530 }
@@ -598,8 +601,8 @@ export class Project {
598601 await this . _compile ( 'https://deno.land/x/aleph/renderer.ts' , { forceTarget : 'es2020' } )
599602 await this . _createMainModule ( )
600603
601- const { renderPage, renderHead } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile )
602- this . #renderer = { renderPage, renderHead }
604+ const { renderPage, renderHead, renderScripts } = await import ( 'file://' + this . #modules. get ( '//deno.land/x/aleph/renderer.js' ) ! . jsFile )
605+ this . #renderer = { renderPage, renderHead, renderScripts }
603606
604607 log . info ( colors . bold ( 'Aleph.js' ) )
605608 if ( '__file' in this . config ) {
@@ -885,10 +888,10 @@ export class Project {
885888 break
886889 }
887890 }
888- if ( / ^ h t t p s ? : \/ \/ [ 0 - 9 a - z \. \- ] + \/ r e a c t ( @ [ 0 - 9 a - z \. \- ] + ) ? \/ ? $ / i. test ( url ) ) {
891+ if ( / ^ h t t p s ? : \/ \/ [ 0 - 9 a - z \. \- ] + \/ r e a c t ( @ [ 0 - 9 a - z \. \- ] + ) ? \/ ? $ / i. test ( dlUrl ) ) {
889892 dlUrl = this . config . reactUrl
890893 }
891- if ( / ^ h t t p s ? : \/ \/ [ 0 - 9 a - z \. \- ] + \/ r e a c t \- d o m ( @ [ 0 - 9 a - z \. \- ] + ) ? ( \/ s e r v e r ) ? \/ ? $ / i. test ( url ) ) {
894+ if ( / ^ h t t p s ? : \/ \/ [ 0 - 9 a - z \. \- ] + \/ r e a c t \- d o m ( @ [ 0 - 9 a - z \. \- ] + ) ? ( \/ s e r v e r ) ? \/ ? $ / i. test ( dlUrl ) ) {
892895 dlUrl = this . config . reactDomUrl
893896 if ( / \/ s e r v e r \/ ? $ / i. test ( url ) ) {
894897 dlUrl += '/server'
@@ -966,7 +969,6 @@ export class Project {
966969 let css : string = sourceContent
967970 if ( mod . id . endsWith ( '.less' ) ) {
968971 try {
969- // todo: sourceMap
970972 const output = await less . render ( sourceContent || '/* empty content */' )
971973 css = output . css
972974 } catch ( error ) {
@@ -983,7 +985,7 @@ export class Project {
983985 } )
984986 css = ( await postcss ( plugins ) . process ( css ) . async ( ) ) . content
985987 if ( this . isDev ) {
986- css = String ( css ) . trim ( )
988+ css = css . trim ( )
987989 } else {
988990 const output = cleanCSS . minify ( css )
989991 css = output . styles
@@ -995,7 +997,7 @@ export class Project {
995997 ) ) } ;`,
996998 `applyCSS(${ JSON . stringify ( url ) } , ${ JSON . stringify ( this . isDev ? `\n${ css } \n` : css ) } );` ,
997999 ] . join ( this . isDev ? '\n' : '' )
998- mod . jsSourceMap = ''
1000+ mod . jsSourceMap = '' // todo: sourceMap
9991001 mod . hash = getHash ( css )
10001002 } else if ( mod . loader === 'markdown' ) {
10011003 const { __content, ...props } = safeLoadFront ( sourceContent )
@@ -1250,7 +1252,7 @@ export class Project {
12501252 this . #rendered. set ( url . pagePath , new Map ( ) )
12511253 }
12521254 }
1253- const ret : RenderResult = { url, status : url . pagePath === '' ? 404 : 200 , head : [ ] , body : '<main></main>' , data : null }
1255+ const ret : RenderResult = { url, status : url . pagePath === '' ? 404 : 200 , head : [ ] , scripts : [ ] , body : '<main></main>' , data : null }
12541256 Object . assign ( window , {
12551257 location : {
12561258 protocol : 'http:' ,
@@ -1292,6 +1294,7 @@ export class Project {
12921294 ...pageModuleTree . map ( ( { id } ) => this . _lookupAsyncDeps ( id ) . filter ( ( { url } ) => reStyleModuleExt . test ( url ) ) )
12931295 ] . flat ( ) )
12941296 ret . head = head
1297+ ret . scripts = await this . #renderer. renderScripts ( )
12951298 ret . body = `<main>${ html } </main>`
12961299 ret . data = data
12971300 this . #rendered. get ( url . pagePath ) ! . set ( key , ret )
@@ -1308,7 +1311,7 @@ export class Project {
13081311 }
13091312
13101313 private async _render404Page ( url : RouterURL = { locale : this . config . defaultLocale , pagePath : '' , pathname : '/' , params : { } , query : new URLSearchParams ( ) } ) {
1311- const ret : RenderResult = { url, status : 404 , head : [ ] , body : '<main></main>' , data : null }
1314+ const ret : RenderResult = { url, status : 404 , head : [ ] , scripts : [ ] , body : '<main></main>' , data : null }
13121315 try {
13131316 const e404Module = this . #modules. get ( '/404.js' )
13141317 const { default : E404 } = e404Module ? await import ( 'file://' + e404Module . jsFile ) : { } as any
@@ -1317,6 +1320,7 @@ export class Project {
13171320 e404Module ? this . _lookupAsyncDeps ( e404Module . id ) . filter ( ( { url } ) => reStyleModuleExt . test ( url ) ) : [ ]
13181321 ] . flat ( ) )
13191322 ret . head = head
1323+ ret . scripts = await this . #renderer. renderScripts ( )
13201324 ret . body = `<main>${ html } </main>`
13211325 ret . data = data
13221326 } catch ( err ) {
0 commit comments