@lomray/vite-ssr-boost 8.0.0 → 8.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node/production.d.ts +19 -0
- package/node/production.js +2 -0
- package/node/production.js.map +1 -0
- package/package.json +9 -1
- package/services/route-assets.d.ts +64 -0
- package/services/route-assets.js +2 -0
- package/services/route-assets.js.map +1 -0
- package/services/ssr-manifest.d.ts +11 -52
- package/services/ssr-manifest.js +1 -1
- package/services/ssr-manifest.js.map +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ICreateHandlerOptions, IHtmlShell } from '../core/handler.js';
|
|
2
|
+
interface ILoadHtmlShellOptions {
|
|
3
|
+
indexFile: string;
|
|
4
|
+
outlet?: string;
|
|
5
|
+
}
|
|
6
|
+
interface IRouteAssetPreparerOptions {
|
|
7
|
+
buildDir: string;
|
|
8
|
+
modulePreload?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Read a built document once and supply a fresh shell for each request.
|
|
12
|
+
*/
|
|
13
|
+
declare const loadHtmlShell: ({ indexFile, outlet, }: ILoadHtmlShellOptions) => Promise<() => IHtmlShell>;
|
|
14
|
+
/**
|
|
15
|
+
* Inject matched route assets using a manifest cache owned by this preparer.
|
|
16
|
+
*/
|
|
17
|
+
declare const createRouteAssetPreparer: <TAppProps = Record<string, any>>({ buildDir, modulePreload, }: IRouteAssetPreparerOptions) => NonNullable<ICreateHandlerOptions<TAppProps>["prepare"]>;
|
|
18
|
+
export { createRouteAssetPreparer, loadHtmlShell };
|
|
19
|
+
export type { IHtmlShell, ILoadHtmlShellOptions, IRouteAssetPreparerOptions };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{readFile as t}from"node:fs/promises";import e from"../services/route-assets.js";const o=async({indexFile:e,outlet:o="\x3c!--ssr-outlet--\x3e"})=>{const n=(await t(e,"utf8")).split(o);if(!o||2!==n.length)throw new Error(`Invalid HTML shell in "${e}": expected exactly one non-empty outlet ${JSON.stringify(o)}.`);const[s,r]=n;return()=>({header:s,footer:r})},n=({buildDir:t,modulePreload:o=!1})=>{const n=new e(t,o);return async({context:t,executionContext:e})=>{const o=n.injectAssets(t);o.has("Link")&&await(e?.onEarlyHints?.(o))}};export{n as createRouteAssetPreparer,o as loadHtmlShell};
|
|
2
|
+
//# sourceMappingURL=production.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production.js","sources":["../../src/node/production.ts"],"sourcesContent":[null],"names":["loadHtmlShell","async","indexFile","outlet","parts","readFile","split","length","Error","JSON","stringify","header","footer","createRouteAssetPreparer","buildDir","modulePreload","assets","RouteAssets","context","executionContext","hints","injectAssets","has","onEarlyHints"],"mappings":"uFAiBA,MAAMA,EAAgBC,OACpBC,YACAC,SAAS,8BAET,MACMC,SADaC,EAASH,EAAW,SACpBI,MAAMH,GAEzB,IAAKA,GAA2B,IAAjBC,EAAMG,OACnB,MAAM,IAAIC,MACR,0BAA0BN,6CAAqDO,KAAKC,UAAUP,OAIlG,MAAOQ,EAAQC,GAAUR,EAEzB,MAAO,KAAA,CAASO,SAAQC,YAMpBC,EAA2B,EAC/BC,WACAC,iBAAgB,MAEhB,MAAMC,EAAS,IAAIC,EAAYH,EAAUC,GAEzC,OAAOd,OAASiB,UAASC,uBACvB,MAAMC,EAAQJ,EAAOK,aAAaH,GAE9BE,EAAME,IAAI,eACNH,GAAkBI,eAAeH"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lomray/vite-ssr-boost",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.1.0-beta.1",
|
|
4
4
|
"description": "Vite plugin for create awesome SSR or SPA applications on React.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
|
+
"./node/production": {
|
|
8
|
+
"types": "./node/production.d.ts",
|
|
9
|
+
"default": "./node/production.js"
|
|
10
|
+
},
|
|
11
|
+
"./node/production.js": {
|
|
12
|
+
"types": "./node/production.d.ts",
|
|
13
|
+
"default": "./node/production.js"
|
|
14
|
+
},
|
|
7
15
|
"./*.js": {
|
|
8
16
|
"types": "./*.d.ts",
|
|
9
17
|
"default": "./*.js"
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { RouterState, StaticHandlerContext } from 'react-router';
|
|
2
|
+
declare enum AssetType {
|
|
3
|
+
style = "style",
|
|
4
|
+
script = "script",
|
|
5
|
+
image = "image",
|
|
6
|
+
font = "font"
|
|
7
|
+
}
|
|
8
|
+
interface IAsset {
|
|
9
|
+
type: AssetType;
|
|
10
|
+
url: string;
|
|
11
|
+
weight: number;
|
|
12
|
+
isNested: boolean;
|
|
13
|
+
isPreload: boolean;
|
|
14
|
+
content?: string;
|
|
15
|
+
}
|
|
16
|
+
type TAssets = {
|
|
17
|
+
[id: string]: IAsset;
|
|
18
|
+
};
|
|
19
|
+
interface IInjectAssetsContext {
|
|
20
|
+
html: {
|
|
21
|
+
header: string;
|
|
22
|
+
};
|
|
23
|
+
routerContext?: StaticHandlerContext;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Load and inject route assets with an independent cache for one build.
|
|
27
|
+
*/
|
|
28
|
+
declare class RouteAssets {
|
|
29
|
+
protected readonly outputDir: string;
|
|
30
|
+
protected readonly modulePreload: boolean;
|
|
31
|
+
protected routesAssets: Record<string, IAsset[]> | null;
|
|
32
|
+
constructor(buildDir: string, modulePreload?: boolean);
|
|
33
|
+
/**
|
|
34
|
+
* Development manifests override this to inject inline styles.
|
|
35
|
+
*/
|
|
36
|
+
protected get isDev(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Get assets manifest file name.
|
|
39
|
+
*/
|
|
40
|
+
protected getAssetsManifestFile(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Load assets manifest
|
|
43
|
+
*/
|
|
44
|
+
protected loadAssetsManifest(): Record<string, IAsset[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Sort assets
|
|
47
|
+
*/
|
|
48
|
+
protected sortAssets(assets: IAsset[]): IAsset[];
|
|
49
|
+
/**
|
|
50
|
+
* Get route assets
|
|
51
|
+
*/
|
|
52
|
+
protected getAssets(routes?: RouterState['matches']): IAsset[];
|
|
53
|
+
/**
|
|
54
|
+
* Build preload hints without depending on a particular HTTP transport.
|
|
55
|
+
*/
|
|
56
|
+
getEarlyHints(assets: IAsset[]): Headers;
|
|
57
|
+
/**
|
|
58
|
+
* Inject route assets to head html
|
|
59
|
+
*/
|
|
60
|
+
injectAssets({ routerContext, html }: IInjectAssetsContext): Headers;
|
|
61
|
+
}
|
|
62
|
+
export { AssetType };
|
|
63
|
+
export type { IAsset, TAssets };
|
|
64
|
+
export default RouteAssets;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import e from"node:fs";import t from"node:path";var s;!function(e){e.style="style",e.script="script",e.image="image",e.font="font"}(s||(s={}));class r{outputDir;modulePreload;routesAssets=null;constructor(e,s=!1){this.outputDir=t.resolve(e),this.modulePreload=s}get isDev(){return!1}getAssetsManifestFile(){return t.join(this.outputDir,"server","assets-manifest.json")}loadAssetsManifest(){if(null!==this.routesAssets)return this.routesAssets;const t=this.getAssetsManifestFile();return e.existsSync(t)?(this.routesAssets=JSON.parse(e.readFileSync(t,{encoding:"utf-8"})),this.routesAssets):{}}sortAssets(e){return e.sort((e,t)=>e.weight===t.weight?Number(e.isNested)-Number(t.isNested):e.weight-t.weight)}getAssets(e){const t=e?.map(({route:e})=>e.id).filter(Boolean)??[];if(!t.length)return[];const s=this.loadAssetsManifest();return this.sortAssets(t.map(e=>s[e]).flat().filter(Boolean))}getEarlyHints(e){const t=new Headers;return e.forEach(({type:e,url:s})=>{e&&["style","script"].includes(e)&&t.append("Link",`<${s}>; rel=preload; as=${e}`)}),t}injectAssets({routerContext:e,html:t}){const r=this.getAssets(e?.matches),i=r.map(({type:e,url:t,isPreload:r,content:i=""})=>{switch(e){case s.style:return this.isDev?`<style data-vite-dev-id="${t}">${i}</style>`:`<link rel="stylesheet" href="${t}">`;case s.script:return r?this.modulePreload?`<link rel="modulepreload" as="script" crossorigin href="${t}">`:null:`<script async type="module" crossorigin src="${t}"><\/script>`}return null}).filter(Boolean);return t.header=t.header.replace("</head>",`${i.join("\n")}</head>`),this.getEarlyHints(r)}}export{s as AssetType,r as default};
|
|
2
|
+
//# sourceMappingURL=route-assets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-assets.js","sources":["../../src/services/route-assets.ts"],"sourcesContent":[null],"names":["AssetType","RouteAssets","outputDir","modulePreload","routesAssets","constructor","buildDir","this","path","resolve","isDev","getAssetsManifestFile","join","loadAssetsManifest","manifestFile","fs","existsSync","JSON","parse","readFileSync","encoding","sortAssets","assets","sort","a","b","weight","Number","isNested","getAssets","routes","routeIds","map","route","id","filter","Boolean","length","routeId","flat","getEarlyHints","headers","Headers","forEach","type","url","includes","append","injectAssets","routerContext","html","matches","htmlAssets","isPreload","content","style","script","header","replace"],"mappings":"gDAIA,IAAKA,GAAL,SAAKA,GACHA,EAAA,MAAA,QACAA,EAAA,OAAA,SACAA,EAAA,MAAA,QACAA,EAAA,KAAA,MACD,CALD,CAAKA,IAAAA,EAAS,CAAA,IA4Bd,MAAMC,EACeC,UAEAC,cAETC,aAAgD,KAE1D,WAAAC,CAAYC,EAAkBH,GAAgB,GAC5CI,KAAKL,UAAYM,EAAKC,QAAQH,GAC9BC,KAAKJ,cAAgBA,CACvB,CAKA,SAAcO,GACZ,OAAO,CACT,CAKU,qBAAAC,GACR,OAAOH,EAAKI,KAAKL,KAAKL,UAAW,SAAU,uBAC7C,CAKU,kBAAAW,GACR,GAA0B,OAAtBN,KAAKH,aACP,OAAOG,KAAKH,aAGd,MAAMU,EAAeP,KAAKI,wBAE1B,OAAKI,EAAGC,WAAWF,IAInBP,KAAKH,aAAea,KAAKC,MAAMH,EAAGI,aAAaL,EAAc,CAAEM,SAAU,WAKlEb,KAAKH,cARH,CAAA,CASX,CAKU,UAAAiB,CAAWC,GACnB,OAAOA,EAAOC,KAAK,CAACC,EAAGC,IACrBD,EAAEE,SAAWD,EAAEC,OAASC,OAAOH,EAAEI,UAAYD,OAAOF,EAAEG,UAAYJ,EAAEE,OAASD,EAAEC,OAEnF,CAKU,SAAAG,CAAUC,GAClB,MAAMC,EAAWD,GAAQE,IAAI,EAAGC,WAAYA,EAAMC,IAAIC,OAAOC,UAAY,GAEzE,IAAKL,EAASM,OACZ,MAAO,GAGT,MAAMjC,EAAeG,KAAKM,qBAE1B,OAAON,KAAKc,WACVU,EACGC,IAAKM,GAAYlC,EAAakC,IAC9BC,OACAJ,OAAOC,SAEd,CAKO,aAAAI,CAAclB,GACnB,MAAMmB,EAAU,IAAIC,QAUpB,OARApB,EAAOqB,QAAQ,EAAGC,OAAMC,UACjBD,GAAS,CAAC,QAAS,UAAUE,SAASF,IAI3CH,EAAQM,OAAO,OAAQ,IAAIF,uBAAyBD,OAG/CH,CACT,CAKO,YAAAO,EAAaC,cAAEA,EAAaC,KAAEA,IACnC,MAAM5B,EAASf,KAAKsB,UAAUoB,GAAeE,SACvCC,EAAa9B,EAChBU,IAAI,EAAGY,OAAMC,MAAKQ,YAAWC,UAAU,OACtC,OAAQV,GACN,KAAK5C,EAAUuD,MACb,OAAOhD,KAAKG,MACR,4BAA4BmC,MAAQS,YACpC,gCAAgCT,MAEtC,KAAK7C,EAAUwD,OACb,OAAOH,EACH9C,KAAKJ,cAEH,2DAA2D0C,MAC3D,KACF,gDAAgDA,gBAGxD,OAAO,OAERV,OAAOC,SAIV,OAFAc,EAAKO,OAASP,EAAKO,OAAOC,QAAQ,UAAW,GAAGN,EAAWxC,KAAK,gBAEzDL,KAAKiC,cAAclB,EAC5B"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { RouterState
|
|
1
|
+
import type { RouterState } from 'react-router';
|
|
2
2
|
import type { Alias, ModuleNode, RenderBuiltAssetUrl } from 'vite';
|
|
3
3
|
import type { TRoutesTree } from './parse-routes.js';
|
|
4
4
|
import PathNormalize from './path-normalize.js';
|
|
5
|
+
import type { IAsset, TAssets } from './route-assets.js';
|
|
6
|
+
import RouteAssets, { AssetType } from './route-assets.js';
|
|
5
7
|
import type ServerConfig from './server-config.js';
|
|
6
8
|
interface ISsrManifestParams {
|
|
7
9
|
buildDir?: string;
|
|
@@ -18,33 +20,10 @@ interface IManifest {
|
|
|
18
20
|
imports: string[];
|
|
19
21
|
};
|
|
20
22
|
}
|
|
21
|
-
declare enum AssetType {
|
|
22
|
-
style = "style",
|
|
23
|
-
script = "script",
|
|
24
|
-
image = "image",
|
|
25
|
-
font = "font"
|
|
26
|
-
}
|
|
27
|
-
interface IAsset {
|
|
28
|
-
type: AssetType;
|
|
29
|
-
url: string;
|
|
30
|
-
weight: number;
|
|
31
|
-
isNested: boolean;
|
|
32
|
-
isPreload: boolean;
|
|
33
|
-
content?: string;
|
|
34
|
-
}
|
|
35
|
-
type TAssets = {
|
|
36
|
-
[id: string]: IAsset;
|
|
37
|
-
};
|
|
38
|
-
interface IInjectAssetsContext {
|
|
39
|
-
html: {
|
|
40
|
-
header: string;
|
|
41
|
-
};
|
|
42
|
-
routerContext?: StaticHandlerContext;
|
|
43
|
-
}
|
|
44
23
|
/**
|
|
45
24
|
* Working with SSR Manifest file
|
|
46
25
|
*/
|
|
47
|
-
declare class SsrManifest {
|
|
26
|
+
declare class SsrManifest extends RouteAssets {
|
|
48
27
|
/**
|
|
49
28
|
* Singleton
|
|
50
29
|
*/
|
|
@@ -69,10 +48,6 @@ declare class SsrManifest {
|
|
|
69
48
|
* Client manifest file name
|
|
70
49
|
*/
|
|
71
50
|
protected readonly manifestName = "manifest.json";
|
|
72
|
-
/**
|
|
73
|
-
* Assets manifest file name
|
|
74
|
-
*/
|
|
75
|
-
protected readonly assetsManifest = "assets-manifest.json";
|
|
76
51
|
/**
|
|
77
52
|
* Vite resolve aliases
|
|
78
53
|
*/
|
|
@@ -85,10 +60,6 @@ declare class SsrManifest {
|
|
|
85
60
|
* Vite renderBuiltUrl config func
|
|
86
61
|
*/
|
|
87
62
|
protected readonly renderBuiltUrl?: RenderBuiltAssetUrl;
|
|
88
|
-
/**
|
|
89
|
-
* Loaded assets manifest file
|
|
90
|
-
*/
|
|
91
|
-
protected routesAssets: Record<string, IAsset[]> | null;
|
|
92
63
|
/**
|
|
93
64
|
* @constructor
|
|
94
65
|
*/
|
|
@@ -98,29 +69,25 @@ declare class SsrManifest {
|
|
|
98
69
|
*/
|
|
99
70
|
static get(config: ServerConfig, params?: ISsrManifestParams): SsrManifest;
|
|
100
71
|
/**
|
|
101
|
-
*
|
|
72
|
+
* Use inline styles while the managed Vite server is running.
|
|
73
|
+
*/
|
|
74
|
+
protected get isDev(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Get output dir.
|
|
102
77
|
*/
|
|
103
78
|
protected getOutDir(): string;
|
|
104
79
|
/**
|
|
105
|
-
*
|
|
80
|
+
* Keep the managed server's build path resolution.
|
|
106
81
|
*/
|
|
107
82
|
protected getAssetsManifestFile(): string;
|
|
108
83
|
/**
|
|
109
84
|
* Load client ssr manifest
|
|
110
85
|
*/
|
|
111
86
|
protected loadClientManifest(): IManifest;
|
|
112
|
-
/**
|
|
113
|
-
* Load assets manifest
|
|
114
|
-
*/
|
|
115
|
-
protected loadAssetsManifest(): Record<string, IAsset[]>;
|
|
116
87
|
/**
|
|
117
88
|
* Same as 'getAsyncRoutesIds' but for routes tree from 'ParseRoutes'
|
|
118
89
|
*/
|
|
119
90
|
protected getRoutesTreeIds(routes: TRoutesTree[], index?: string): Record<string, string | undefined>;
|
|
120
|
-
/**
|
|
121
|
-
* Sort assets
|
|
122
|
-
*/
|
|
123
|
-
protected sortAssets(assets: IAsset[]): IAsset[];
|
|
124
91
|
/**
|
|
125
92
|
* Get recursive module assets
|
|
126
93
|
*/
|
|
@@ -130,7 +97,7 @@ declare class SsrManifest {
|
|
|
130
97
|
*/
|
|
131
98
|
buildRoutesManifest(): void;
|
|
132
99
|
/**
|
|
133
|
-
* Get route assets
|
|
100
|
+
* Get route assets from Vite in development or the built manifest in production.
|
|
134
101
|
*/
|
|
135
102
|
protected getAssets(routes?: RouterState['matches']): IAsset[];
|
|
136
103
|
/**
|
|
@@ -157,13 +124,5 @@ declare class SsrManifest {
|
|
|
157
124
|
* Get asset type
|
|
158
125
|
*/
|
|
159
126
|
protected getAssetType(asset: string): AssetType | null;
|
|
160
|
-
/**
|
|
161
|
-
* Build preload hints without depending on a particular HTTP transport.
|
|
162
|
-
*/
|
|
163
|
-
getEarlyHints(assets: IAsset[]): Headers;
|
|
164
|
-
/**
|
|
165
|
-
* Inject route assets to head html
|
|
166
|
-
*/
|
|
167
|
-
injectAssets({ routerContext, html }: IInjectAssetsContext): Headers;
|
|
168
127
|
}
|
|
169
128
|
export default SsrManifest;
|
package/services/ssr-manifest.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"node:fs";import s from"node:path";import t from"chalk";import i from"./parse-routes.js";import r from"./path-normalize.js";
|
|
1
|
+
import e from"node:fs";import s from"node:path";import t from"chalk";import i from"./parse-routes.js";import r from"./path-normalize.js";import o,{AssetType as a}from"./route-assets.js";class n extends o{static instance=null;config;pathNormalize;root;buildDir;manifestName="manifest.json";viteAliases;basename;renderBuiltUrl;constructor(e,{buildDir:t,viteAliases:i,basename:o,renderBuiltUrl:a}={}){super(s.resolve(e.getParams().root,t||""),e.isModulePreload),this.config=e,this.root=e.getParams().root,this.buildDir=t,this.viteAliases=i??e.getVite()?.config?.resolve.alias,this.pathNormalize=new r(e,i),this.basename=o,this.renderBuiltUrl=a}static get(e,s={}){return null===n.instance&&(n.instance=new n(e,s)),n.instance}get isDev(){return Boolean(this.config.getVite())}getOutDir(){return s.resolve(this.root,this.buildDir||"")}getAssetsManifestFile(){return`${this.getOutDir()}/server/assets-manifest.json`}loadClientManifest(){const t=s.resolve(this.root,`${this.buildDir||""}/client/.vite`),i=`${t}/${this.manifestName}`;if(!e.existsSync(i))return{};const r=JSON.parse(e.readFileSync(i,{encoding:"utf-8"}));return e.rmSync(i),0===e.readdirSync(t).length&&e.rmSync(t,{recursive:!0}),r}getRoutesTreeIds(e,s){const t={};return e.forEach((e,i)=>{const r=[s,String(i)].filter(Boolean).join("-");e.import&&(t[r]=this.pathNormalize.getAppPath(e.import)),e.children.length>0&&Object.assign(t,this.getRoutesTreeIds(e.children,r))}),t}getRouteAssets(e,t,i=!1){const r=[...t?.assets??[],...t?.css??[],t?.file].reduce((e,r)=>{if(r){const o=this.getAssetType(r),a=t.isEntry&&t.file===r;if(o){const t=s.posix.normalize(`${this.basename}/${r}`),n=this.renderBuiltUrl?.(t,{type:"asset",ssr:!0,hostId:"",hostType:t.split(".").at(-1)?.toLowerCase()});e[r]={url:"string"==typeof n?n:t,weight:a?1.9:this.getAssetWeight(r),type:o,isNested:i,isPreload:!a}}}return e},{});return t?.imports?.length&&t.imports.forEach(s=>{const t=e[s];t&&Object.assign(r,this.getRouteAssets(e,t,!0))}),r}buildRoutesManifest(){const s=this.loadClientManifest(),t=new i(this.config,this.viteAliases),r=this.getRoutesTreeIds(t.parse()),o=this.pathNormalize.getImportPostfix(),a={};Object.entries(r).forEach(([e,t])=>{const i=o.find(e=>void 0!==s[`${t}${e}`]),r=s[`${t}${i||""}`];a[e]=this.sortAssets(Object.values(this.getRouteAssets(s,r)))}),e.writeFileSync(this.getAssetsManifestFile(),JSON.stringify(a,null,2),{encoding:"utf-8"})}getAssets(e){return this.isDev?this.getAssetsDev(e):super.getAssets(e)}getDevModules(e){const t=e?.map(({route:e})=>this.pathNormalize.getAppPath(e?.pathId,!0)).filter(Boolean)??[],i=this.pathNormalize.getImportPostfix(),r=this.config.getPluginConfig(),o=[r?.clientFile??"client.ts",r?.serverFile??"server.ts"].map(e=>s.resolve(this.root,e)),a=[];return[...o,...t].forEach(e=>{for(const s of i){const t=this.config.getVite()?.moduleGraph.getModuleById(`${e}${s}`);if(t){a.push(t);break}}}),a}async prepareDevAssets(e){const s=this.config.getVite();if(!s)return;const t=new Set,i=async e=>{t.has(e.url)||(t.add(e.url),e.file&&/\.(?:css|less|s[ac]ss|styl(?:us)?|pcss|postcss)$/.test(e.file)&&await s.transformRequest(e.url),await Promise.all([...e.importedModules].map(i)))};await Promise.all(this.getDevModules(e).map(i))}getAssetsDev(e){const s=Object.assign({},...this.getDevModules(e).map(e=>this.getModuleAssets(e)));return Object.values(s)}getModuleAssets(e,s=new Set){const i=e?.importedModules??e?.clientImportedModules;if(!i?.size||s.has(e.file))return{};let r={};return s.add(e.file),i.forEach(e=>{const{file:i,transformResult:o}=e,n=i?.split(".").at(-1);if(i&&n&&["css","scss","sass","less","styl","stylus","pcss","postcss"].includes(n)){const e=o?.code.match(/__vite__css\s+=\s+"(?<css>.+)"/)?.groups?.css;if(e)try{r[i]={type:a.style,url:i,weight:this.getAssetWeight(i),content:JSON.parse(`{"style": "${e}"}`).style,isNested:Boolean(s.size),isPreload:!1}}catch{console.warn(t.yellowBright("Failed to parse style: ",i))}}else r={...r,...this.getModuleAssets(e,s)}}),r}getAssetWeight(e){switch(this.getAssetType(e)){case a.style:return 1;case a.script:return 2;default:return 3}}getAssetType(e){const s=e.split(".").at(-1)?.toLowerCase();switch(s){case"css":case"scss":return a.style;case"js":return a.script;case"svg":case"jpg":case"jpeg":case"png":case"webp":case"gif":case"ico":return a.image;case"ttf":case"otf":case"woff":case"woff2":return a.font;default:return null}}}export{n as default};
|
|
2
2
|
//# sourceMappingURL=ssr-manifest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-manifest.js","sources":["../../src/services/ssr-manifest.ts"],"sourcesContent":[null],"names":["
|
|
1
|
+
{"version":3,"file":"ssr-manifest.js","sources":["../../src/services/ssr-manifest.ts"],"sourcesContent":[null],"names":["SsrManifest","RouteAssets","static","config","pathNormalize","root","buildDir","manifestName","viteAliases","basename","renderBuiltUrl","constructor","super","path","resolve","getParams","isModulePreload","this","getVite","alias","PathNormalize","get","params","instance","isDev","Boolean","getOutDir","getAssetsManifestFile","loadClientManifest","clientManifestDir","clientSsrManifest","fs","existsSync","result","JSON","parse","readFileSync","encoding","rmSync","readdirSync","length","recursive","getRoutesTreeIds","routes","index","forEach","route","routeIndex","routeId","String","filter","join","import","getAppPath","children","Object","assign","getRouteAssets","manifest","module","isNested","assets","css","file","reduce","res","asset","type","getAssetType","isEntry","filename","posix","normalize","modifiedFilename","ssr","hostId","hostType","split","at","toLowerCase","url","weight","getAssetWeight","isPreload","imports","nestedAsset","nestedModule","buildRoutesManifest","routesService","ParseRoutes","routesPaths","postfixes","getImportPostfix","entries","routePath","routePostfix","find","postfix","undefined","routeMeta","sortAssets","values","writeFileSync","stringify","getAssets","getAssetsDev","getDevModules","routeIds","map","pathId","pluginConfig","getPluginConfig","rootIds","clientFile","serverFile","modules","moduleId","ext","moduleGraph","getModuleById","push","prepareDevAssets","vite","visited","Set","visit","async","has","add","test","transformRequest","Promise","all","importedModules","getModuleAssets","skipModules","clientImportedModules","size","subModule","transformResult","includes","code","match","groups","AssetType","style","content","console","warn","chalk","yellowBright","script","image","font"],"mappings":"0LAiCA,MAAMA,UAAoBC,EAIdC,gBAAsC,KAK7BC,OAKAC,cAKAC,KAKAC,SAKAC,aAAe,gBAKfC,YAKAC,SAKAC,eAKnB,WAAAC,CACER,GACAG,SAAEA,EAAQE,YAAEA,EAAWC,SAAEA,EAAQC,eAAEA,GAAuC,IAE1EE,MAAMC,EAAKC,QAAQX,EAAOY,YAAYV,KAAMC,GAAY,IAAKH,EAAOa,iBAEpEC,KAAKd,OAASA,EACdc,KAAKZ,KAAOF,EAAOY,YAAYV,KAC/BY,KAAKX,SAAWA,EAChBW,KAAKT,YAAcA,GAAeL,EAAOe,WAAWf,QAAQW,QAAQK,MACpEF,KAAKb,cAAgB,IAAIgB,EAAcjB,EAAQK,GAC/CS,KAAKR,SAAWA,EAChBQ,KAAKP,eAAiBA,CACxB,CAKO,UAAOW,CAAIlB,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