@lomray/vite-ssr-boost 2.0.0 → 2.0.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/README.md
CHANGED
|
@@ -247,7 +247,7 @@ const routes: RouteObject[] = [
|
|
|
247
247
|
Component: HomePage, // support
|
|
248
248
|
element: <AppLayout />, // support
|
|
249
249
|
lazy: () => import('./pages/home'), // support
|
|
250
|
-
lazy: () => import(importPath), // not support
|
|
250
|
+
lazy: () => import(importPath), // not support, but you can move logic in separate file and import it with supported case
|
|
251
251
|
lazy: () => { // not support
|
|
252
252
|
return import('./pages/home');
|
|
253
253
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lomray/vite-ssr-boost",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Vite plugin for create awesome SSR or SPA applications on React.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -30,8 +30,7 @@
|
|
|
30
30
|
"lint:check": "eslint --ext \".ts,.tsx\" \"src/**/*.{ts,tsx,*.ts,*tsx}\"",
|
|
31
31
|
"lint:format": "eslint --fix --ext \".ts,.tsx\" \"src/**/*.{ts,tsx,*.ts,*tsx}\"",
|
|
32
32
|
"ts:check": "tsc --project ./tsconfig.json --skipLibCheck --noemit",
|
|
33
|
-
"test": "mocha --no-warnings __tests__ --recursive --unhandled-rejections=strict --exit"
|
|
34
|
-
"test:watch": "mocha --no-warnings __tests__ --recursive --unhandled-rejections=strict"
|
|
33
|
+
"test": "mocha --no-warnings __tests__ --recursive --unhandled-rejections=strict --exit"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
36
|
"chalk": "^5.3.0",
|
|
@@ -67,7 +66,6 @@
|
|
|
67
66
|
"husky": "^8.0.3",
|
|
68
67
|
"lint-staged": "^15.2.0",
|
|
69
68
|
"mocha": "^10.2.0",
|
|
70
|
-
"nodemon": "^3.0.2",
|
|
71
69
|
"prettier": "^3.1.0",
|
|
72
70
|
"rollup": "^4.6.1",
|
|
73
71
|
"rollup-plugin-copy": "^3.5.0",
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{extname as e}from"node:path";import r from"../constants/plugin-name.js";import
|
|
1
|
+
import{extname as e}from"node:path";import r from"../constants/plugin-name.js";import t from"../helpers/is-route-file.js";const s=(e,r=!1)=>{if(r)return e;const t=[...e.matchAll(/import\s+(\w+)\sfrom\s+['"]([^'"]+)['"]/g)].reduce(((e,[,r,t])=>({[r]:t,...e})),{});return e.replace(/(.*?(?:Component|element):[\s<]*(\w+)[^,}]*),*/gs,((e,r,s)=>{const n=t?.[s];return n?`${r},pathId: '${n}',`:r}))},n=(e,t)=>{const s=e.replace(/(lazy)(:\s*)(\(\)\s*=>\s*import\(([^)]+)\))/gs,t?"lazy$2()=>n($3,$4)":"lazy$2()=>n($3)");return e!==s?`import n from '${r}/helpers/import-route';${s}`:e};function o(o={}){const{isSSR:m=!1,isBuild:i=!1,routesPath:p}=o;return{name:`${r}-normalize-route`,enforce:"pre",transform(r,o){const l=e(o).split("?")[0],u=!p||o.includes(p);if(!o.includes("node_modules")&&[".js",".mjs",".ts",".tsx"].includes(l)&&u&&t(r))return{code:n(s(r,i),m),map:{mappings:""}}}}}export{o as default};
|
|
2
2
|
//# sourceMappingURL=normalize-route.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-route.js","sources":["../../src/plugins/normalize-route.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport isRoutesFile from '@helpers/is-route-file';\n\nexport interface IPluginOptions {\n isSSR?: boolean;\n isBuild?: boolean;\n routesPath?: string;\n}\n\n/**\n * Add pathId to route (where pathId - import string)\n * NOTE: only for dev mode\n */\nconst normalizeSyncRoutes = (code: string, isBuild = false): string => {\n if (isBuild) {\n return code;\n }\n\n const imports: Record<string, string> = [\n ...code.matchAll(/import\\s+(\\w+)\\sfrom\\s+['\"]([^'\"]+)['\"]/g),\n ].reduce(\n (res, [, key, value]) => ({\n [key]: value,\n ...res,\n }),\n {},\n );\n\n return code.replace(\n /(.*?(?:Component|element):[\\s<]*(\\w+)[^,]*),*/gs,\n (_, before: string, routeName: string) => {\n const importPath = imports?.[routeName];\n\n if (!importPath) {\n return before;\n }\n\n return `${before},pathId: '${importPath}',`;\n },\n );\n};\n\n/**\n * Add normalize wrapper to lazy imports for client build\n */\nconst normalizeAsyncRoutes = (code: string, isSSR: boolean): string
|
|
1
|
+
{"version":3,"file":"normalize-route.js","sources":["../../src/plugins/normalize-route.ts"],"sourcesContent":["import { extname } from 'node:path';\nimport type { Plugin } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport isRoutesFile from '@helpers/is-route-file';\n\nexport interface IPluginOptions {\n isSSR?: boolean;\n isBuild?: boolean;\n routesPath?: string;\n}\n\n/**\n * Add pathId to route (where pathId - import string)\n * NOTE: only for dev mode\n */\nconst normalizeSyncRoutes = (code: string, isBuild = false): string => {\n if (isBuild) {\n return code;\n }\n\n const imports: Record<string, string> = [\n ...code.matchAll(/import\\s+(\\w+)\\sfrom\\s+['\"]([^'\"]+)['\"]/g),\n ].reduce(\n (res, [, key, value]) => ({\n [key]: value,\n ...res,\n }),\n {},\n );\n\n return code.replace(\n /(.*?(?:Component|element):[\\s<]*(\\w+)[^,}]*),*/gs,\n (_, before: string, routeName: string) => {\n const importPath = imports?.[routeName];\n\n if (!importPath) {\n return before;\n }\n\n return `${before},pathId: '${importPath}',`;\n },\n );\n};\n\n/**\n * Add normalize wrapper to lazy imports for client build\n */\nconst normalizeAsyncRoutes = (code: string, isSSR: boolean): string => {\n const modifiedCode = code.replace(\n /(lazy)(:\\s*)(\\(\\)\\s*=>\\s*import\\(([^)]+)\\))/gs,\n isSSR ? 'lazy$2()=>n($3,$4)' : 'lazy$2()=>n($3)',\n );\n\n if (code !== modifiedCode) {\n return `import n from '${PLUGIN_NAME}/helpers/import-route';${modifiedCode}`;\n }\n\n return code;\n};\n\n/**\n * Add possibility to export route components like FCRoute or FCCRoute\n * Add route path for generating manifest\n * USAGE: { path: '/', lazy: () => import('./pages/home') }\n * @see FCRoute\n * @see FCCRoute\n * @see SsrManifest.getRoutesIds\n * @see importRoute\n * @constructor\n */\nfunction ViteNormalizeRouterPlugin(options: IPluginOptions = {}): Plugin {\n const { isSSR = false, isBuild = false, routesPath } = options;\n\n return {\n name: `${PLUGIN_NAME}-normalize-route`,\n enforce: 'pre',\n transform(code, id) {\n const extName = extname(id).split('?')[0]!;\n const isRoutesPath = !routesPath || id.includes(routesPath);\n\n if (\n id.includes('node_modules') ||\n !['.js', '.mjs', '.ts', '.tsx'].includes(extName) ||\n !isRoutesPath ||\n !isRoutesFile(code)\n ) {\n return;\n }\n\n return {\n code: normalizeAsyncRoutes(normalizeSyncRoutes(code, isBuild), isSSR),\n map: { mappings: '' },\n };\n },\n };\n}\n\nexport default ViteNormalizeRouterPlugin;\n"],"names":["normalizeSyncRoutes","code","isBuild","imports","matchAll","reduce","res","key","value","replace","_","before","routeName","importPath","normalizeAsyncRoutes","isSSR","modifiedCode","PLUGIN_NAME","ViteNormalizeRouterPlugin","options","routesPath","name","enforce","transform","id","extName","extname","split","isRoutesPath","includes","isRoutesFile","map","mappings"],"mappings":"0HAeA,MAAMA,EAAsB,CAACC,EAAcC,GAAU,KACnD,GAAIA,EACF,OAAOD,EAGT,MAAME,EAAkC,IACnCF,EAAKG,SAAS,6CACjBC,QACA,CAACC,GAAK,CAAGC,EAAKC,MAAY,CACxBD,CAACA,GAAMC,KACJF,KAEL,CAAE,GAGJ,OAAOL,EAAKQ,QACV,oDACA,CAACC,EAAGC,EAAgBC,KAClB,MAAMC,EAAaV,IAAUS,GAE7B,OAAKC,EAIE,GAAGF,cAAmBE,MAHpBF,CAGkC,GAE9C,EAMGG,EAAuB,CAACb,EAAcc,KAC1C,MAAMC,EAAef,EAAKQ,QACxB,gDACAM,EAAQ,qBAAuB,mBAGjC,OAAId,IAASe,EACJ,kBAAkBC,2BAAqCD,IAGzDf,CAAI,EAab,SAASiB,EAA0BC,EAA0B,IAC3D,MAAMJ,MAAEA,GAAQ,EAAKb,QAAEA,GAAU,EAAKkB,WAAEA,GAAeD,EAEvD,MAAO,CACLE,KAAM,GAAGJ,oBACTK,QAAS,MACTC,UAAUtB,EAAMuB,GACd,MAAMC,EAAUC,EAAQF,GAAIG,MAAM,KAAK,GACjCC,GAAgBR,GAAcI,EAAGK,SAAST,GAEhD,IACEI,EAAGK,SAAS,iBACX,CAAC,MAAO,OAAQ,MAAO,QAAQA,SAASJ,IACxCG,GACAE,EAAa7B,GAKhB,MAAO,CACLA,KAAMa,EAAqBd,EAAoBC,EAAMC,GAAUa,GAC/DgB,IAAK,CAAEC,SAAU,IAEpB,EAEL"}
|