@lomray/vite-ssr-boost 1.0.0-beta.23 → 1.0.0-beta.24

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.
@@ -1,2 +1,2 @@
1
- const t=t=>/\[.*{.*path:.*lazyNR:.+import/s.test(t);export{t as default};
1
+ const t=t=>/\[.*{.*path:.*lazy:.+import/s.test(t);export{t as default};
2
2
  //# sourceMappingURL=is-route-file.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-route-file.js","sources":["../../src/helpers/is-route-file.ts"],"sourcesContent":["/**\n * Detect route file\n */\nconst isRoutesFile = (code: string): boolean => /\\[.*{.*path:.*lazyNR:.+import/s.test(code);\n\nexport default isRoutesFile;\n"],"names":["isRoutesFile","code","test"],"mappings":"AAGA,MAAMA,EAAgBC,GAA0B,iCAAiCC,KAAKD"}
1
+ {"version":3,"file":"is-route-file.js","sources":["../../src/helpers/is-route-file.ts"],"sourcesContent":["/**\n * Detect route file\n */\nconst isRoutesFile = (code: string): boolean => /\\[.*{.*path:.*lazy:.+import/s.test(code);\n\nexport default isRoutesFile;\n"],"names":["isRoutesFile","code","test"],"mappings":"AAGA,MAAMA,EAAgBC,GAA0B,+BAA+BC,KAAKD"}
@@ -1,7 +1,7 @@
1
1
  import { RouteObject } from 'react-router-dom';
2
2
  import { IDynamicRoute } from "../helpers/import-route.js";
3
3
  type TRouteObjectNR = Omit<RouteObject, 'lazy' | 'children'> & {
4
- lazyNR?: IDynamicRoute;
4
+ lazy?: IDynamicRoute | RouteObject['lazy'];
5
5
  children?: TRouteObject[];
6
6
  };
7
7
  type TRouteObject = RouteObject | TRouteObjectNR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lomray/vite-ssr-boost",
3
- "version": "1.0.0-beta.23",
3
+ "version": "1.0.0-beta.24",
4
4
  "description": "Vite plugin for create awesome SSR or SPA applications on React.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -4,9 +4,12 @@ interface IPluginOptions {
4
4
  }
5
5
  /**
6
6
  * Add possibility to export route components like FCRoute or FCCRoute
7
- * USAGE: { path: '/', lazyNR: () => import('./pages/home') }
7
+ * Add route path for generating manifest
8
+ * USAGE: { path: '/', lazy: () => import('./pages/home') }
8
9
  * @see FCRoute
9
10
  * @see FCCRoute
11
+ * @see SsrManifest.getRoutesIds
12
+ * @see importRoute
10
13
  * @constructor
11
14
  */
12
15
  declare function ViteNormalizeRouterPlugin(options?: IPluginOptions): Plugin;
@@ -1,2 +1,2 @@
1
- import{extname as r}from"node:path";import o from"../constants/plugin-name.js";import s from"../helpers/is-route-file.js";const e=r=>`import n from '${o}/helpers/import-route';${r}`.replace(/(lazyNR|lazy)(:\s*)(\(\)\s*=>\s*import\(([^)]+)\))/gs,"lazy$2()=>n($3,$4)"),t=r=>`import n from '${o}/helpers/import-route';${r}`.replace(/(lazyNR)(:\s*)(\(\)\s*=>\s*import\(([^)]+)\))/gs,"lazy$2()=>n($3)");function n(n={}){const{isSSR:m=!1}=n;return{name:`${o}-normalize-route`,transform:(o,n)=>{const p=r(n).split("?")[0];if(!n.includes("node_modules")&&[".js",".ts",".tsx"].includes(p)&&s(o))return{code:m?e(o):t(o),map:{mappings:""}}}}}export{n as default};
1
+ import{extname as o}from"node:path";import s from"../constants/plugin-name.js";import r from"../helpers/is-route-file.js";const t=(o,r)=>`import n from '${s}/helpers/import-route';${o}`.replace(/(lazy)(:\s*)(\(\)\s*=>\s*import\(([^)]+)\))/gs,r?"lazy$2()=>n($3,$4)":"lazy$2()=>n($3)");function e(e={}){const{isSSR:n=!1}=e;return{name:`${s}-normalize-route`,transform:(s,e)=>{const i=o(e).split("?")[0];if(!e.includes("node_modules")&&[".js",".ts",".tsx"].includes(i)&&r(s))return{code:t(s,n),map:{mappings:""}}}}}export{e 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}\n\n/**\n * Add normalize wrapper to lazy imports for server build\n */\nconst normalizeRoutesSSR = (code: string): string =>\n `import n from '${PLUGIN_NAME}/helpers/import-route';${code}`.replace(\n /(lazyNR|lazy)(:\\s*)(\\(\\)\\s*=>\\s*import\\(([^)]+)\\))/gs,\n 'lazy$2()=>n($3,$4)',\n );\n\n/**\n * Add normalize wrapper to lazy imports for client build\n */\nconst normalizeRoutes = (code: string): string =>\n `import n from '${PLUGIN_NAME}/helpers/import-route';${code}`.replace(\n /(lazyNR)(:\\s*)(\\(\\)\\s*=>\\s*import\\(([^)]+)\\))/gs,\n 'lazy$2()=>n($3)',\n );\n\n/**\n * Add possibility to export route components like FCRoute or FCCRoute\n * USAGE: { path: '/', lazyNR: () => import('./pages/home') }\n * @see FCRoute\n * @see FCCRoute\n * @constructor\n */\nfunction ViteNormalizeRouterPlugin(options: IPluginOptions = {}): Plugin {\n const { isSSR = false } = options;\n\n return {\n name: `${PLUGIN_NAME}-normalize-route`,\n transform: (code, id) => {\n const extName = extname(id).split('?')[0]!;\n\n if (\n id.includes('node_modules') ||\n !['.js', '.ts', '.tsx'].includes(extName) ||\n !isRoutesFile(code)\n ) {\n return;\n }\n\n return {\n code: isSSR ? normalizeRoutesSSR(code) : normalizeRoutes(code),\n map: { mappings: '' },\n };\n },\n };\n}\n\nexport default ViteNormalizeRouterPlugin;\n"],"names":["normalizeRoutesSSR","code","PLUGIN_NAME","replace","normalizeRoutes","ViteNormalizeRouterPlugin","options","isSSR","name","transform","id","extName","extname","split","includes","isRoutesFile","map","mappings"],"mappings":"0HAYA,MAAMA,EAAsBC,GAC1B,kBAAkBC,2BAAqCD,IAAOE,QAC5D,uDACA,sBAMEC,EAAmBH,GACvB,kBAAkBC,2BAAqCD,IAAOE,QAC5D,kDACA,mBAUJ,SAASE,EAA0BC,EAA0B,IAC3D,MAAMC,MAAEA,GAAQ,GAAUD,EAE1B,MAAO,CACLE,KAAM,GAAGN,oBACTO,UAAW,CAACR,EAAMS,KAChB,MAAMC,EAAUC,EAAQF,GAAIG,MAAM,KAAK,GAEvC,IACEH,EAAGI,SAAS,iBACX,CAAC,MAAO,MAAO,QAAQA,SAASH,IAChCI,EAAad,GAKhB,MAAO,CACLA,KAAMM,EAAQP,EAAmBC,GAAQG,EAAgBH,GACzDe,IAAK,CAAEC,SAAU,IAClB,EAGP"}
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}\n\n/**\n * Add normalize wrapper to lazy imports for client build\n */\nconst normalizeRoutes = (code: string, isSSR: boolean): string =>\n `import n from '${PLUGIN_NAME}/helpers/import-route';${code}`.replace(\n /(lazy)(:\\s*)(\\(\\)\\s*=>\\s*import\\(([^)]+)\\))/gs,\n isSSR ? 'lazy$2()=>n($3,$4)' : 'lazy$2()=>n($3)',\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 } = options;\n\n return {\n name: `${PLUGIN_NAME}-normalize-route`,\n transform: (code, id) => {\n const extName = extname(id).split('?')[0]!;\n\n if (\n id.includes('node_modules') ||\n !['.js', '.ts', '.tsx'].includes(extName) ||\n !isRoutesFile(code)\n ) {\n return;\n }\n\n return {\n code: normalizeRoutes(code, isSSR),\n map: { mappings: '' },\n };\n },\n };\n}\n\nexport default ViteNormalizeRouterPlugin;\n"],"names":["normalizeRoutes","code","isSSR","PLUGIN_NAME","replace","ViteNormalizeRouterPlugin","options","name","transform","id","extName","extname","split","includes","isRoutesFile","map","mappings"],"mappings":"0HAYA,MAAMA,EAAkB,CAACC,EAAcC,IACrC,kBAAkBC,2BAAqCF,IAAOG,QAC5D,gDACAF,EAAQ,qBAAuB,mBAanC,SAASG,EAA0BC,EAA0B,IAC3D,MAAMJ,MAAEA,GAAQ,GAAUI,EAE1B,MAAO,CACLC,KAAM,GAAGJ,oBACTK,UAAW,CAACP,EAAMQ,KAChB,MAAMC,EAAUC,EAAQF,GAAIG,MAAM,KAAK,GAEvC,IACEH,EAAGI,SAAS,iBACX,CAAC,MAAO,MAAO,QAAQA,SAASH,IAChCI,EAAab,GAKhB,MAAO,CACLA,KAAMD,EAAgBC,EAAMC,GAC5Ba,IAAK,CAAEC,SAAU,IAClB,EAGP"}