File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ const loadRemoteInfo = async (url: string) => {
3535 throw new Error ( `Could not load remote info from ${ url } ` ) ;
3636}
3737
38+ /**
39+ * Collects the css chunks from all modules rendered during SSR
40+ * @experimental Handling for async chunks is not final and subject to change.
41+ * Eventually a parameter for the rendered html might be added to analyze the async chunks
42+ * @param modules
43+ */
3844export const collectCssChunks = async ( modules : ModuleContextValueType ) => {
3945 const p = Object . values ( modules ) . map ( async ( module ) => {
4046 const info = await loadRemoteInfo ( module . url ) ;
@@ -43,10 +49,14 @@ export const collectCssChunks = async (modules: ModuleContextValueType) => {
4349 info ?. exposes . forEach ( ( exposes ) => {
4450 if ( module . modules . has ( exposes . path ) ) {
4551 const { sync = [ ] , async = [ ] } = exposes . assets ?. css ?? { } ;
46- [ ... sync , ... async ] . forEach ( ( chunk ) => {
52+ sync . forEach ( ( chunk ) => {
4753 const url = new URL ( chunk , module . url ) ;
4854 chunks . push ( `<link rel="stylesheet" href="${ url } ">` )
4955 } ) ;
56+ async . forEach ( ( chunk ) => {
57+ const url = new URL ( chunk , module . url ) ;
58+ chunks . push ( `<link rel="preload" href="${ url } " as="style" onload="this.rel='stylesheet'">` )
59+ } ) ;
5060 }
5161 } )
5262 return chunks ;
You can’t perform that action at this time.
0 commit comments