@appigram/react-code-split-ssr 1.2.14 → 1.2.16
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/lib/bundle.d.ts +7 -0
- package/lib/generate-routes.d.ts +9 -18
- package/lib/generate-routes.js +2 -2
- package/package.json +6 -6
- package/src/bundle.tsx +13 -13
- package/src/generate-routes.tsx +3 -3
- package/src/index.ts +3 -3
- package/tsconfig.json +4 -3
package/lib/bundle.d.ts
ADDED
package/lib/generate-routes.d.ts
CHANGED
|
@@ -1,27 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React from "react";
|
|
2
2
|
export interface IJSXModule {
|
|
3
|
-
default: React.
|
|
3
|
+
default: React.FC | React.ComponentClass;
|
|
4
4
|
}
|
|
5
5
|
export interface ISSRRoute {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
strict?: boolean;
|
|
12
|
-
}
|
|
13
|
-
export interface IRedirects {
|
|
14
|
-
from: string;
|
|
15
|
-
to: string | object;
|
|
16
|
-
push?: boolean;
|
|
6
|
+
caseSensitive?: boolean;
|
|
7
|
+
children?: React.ReactNode;
|
|
8
|
+
element?: any;
|
|
9
|
+
index?: boolean;
|
|
10
|
+
path?: string;
|
|
17
11
|
}
|
|
18
12
|
export interface IOptions {
|
|
19
13
|
pathname: string;
|
|
20
14
|
routes: ISSRRoute[];
|
|
21
|
-
|
|
22
|
-
notFoundComp?: () => React.SFCElement<{
|
|
23
|
-
mod: Promise<IJSXModule>;
|
|
24
|
-
}>;
|
|
15
|
+
notFoundComp?: any;
|
|
25
16
|
}
|
|
26
|
-
declare const generateRoutes: (options?: IOptions) => Promise<
|
|
17
|
+
declare const generateRoutes: (options?: IOptions) => Promise<import("react/jsx-runtime").JSX.Element>;
|
|
27
18
|
export default generateRoutes;
|
package/lib/generate-routes.js
CHANGED
|
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { matchPath, Route, Routes } from "react-router-dom";
|
|
12
|
-
const generateRoutes = (options = {
|
|
12
|
+
const generateRoutes = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (options = {
|
|
13
13
|
pathname: "/",
|
|
14
14
|
routes: [],
|
|
15
|
-
})
|
|
15
|
+
}) {
|
|
16
16
|
if (!Array.isArray(options.routes) || options.routes.length === 0) {
|
|
17
17
|
throw new Error("options.routes must be an non-empty array");
|
|
18
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appigram/react-code-split-ssr",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.16",
|
|
4
4
|
"description": "React code splitting with SSR",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"author": "Eugene Sysmanov",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/react": "^18.
|
|
25
|
+
"@types/react": "^18.3.1",
|
|
26
26
|
"@types/react-router-dom": "^5.3.3",
|
|
27
27
|
"tslint": "^6.1.3",
|
|
28
28
|
"tslint-react": "^5.0.0",
|
|
29
|
-
"typescript": "^5.
|
|
29
|
+
"typescript": "^5.4.5"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"react": "^18.
|
|
33
|
-
"react-dom": "^18.
|
|
34
|
-
"react-router-dom": "^6.
|
|
32
|
+
"react": "^18.3.1",
|
|
33
|
+
"react-dom": "^18.3.1",
|
|
34
|
+
"react-router-dom": "^6.23.0"
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/bundle.tsx
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {useState, useEffect} from 'react'
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
export interface IProps {
|
|
4
|
-
mod: Promise<any
|
|
5
|
-
loading?: React.FC
|
|
4
|
+
mod: Promise<any>;
|
|
5
|
+
loading?: React.FC;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
const Bundle = ({ mod, loading }: IProps) => {
|
|
9
|
-
const [
|
|
9
|
+
const [state, setState] = useState({ mod: null });
|
|
10
10
|
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
(async function () {
|
|
13
|
-
const Mod = await mod
|
|
14
|
-
setState({ mod: Mod.default })
|
|
15
|
-
})()
|
|
16
|
-
}, [])
|
|
13
|
+
const Mod = await mod;
|
|
14
|
+
setState({ mod: Mod.default });
|
|
15
|
+
})();
|
|
16
|
+
}, []);
|
|
17
17
|
|
|
18
|
-
const Mod = state.mod
|
|
19
|
-
const Loading = loading || (() => <div />)
|
|
20
|
-
return state.mod ? <Mod /> : <Loading
|
|
21
|
-
}
|
|
18
|
+
const Mod = state.mod;
|
|
19
|
+
const Loading = loading || (() => <div />);
|
|
20
|
+
return state.mod ? <Mod /> : <Loading />;
|
|
21
|
+
};
|
|
22
22
|
|
|
23
|
-
export default Bundle
|
|
23
|
+
export default Bundle;
|
package/src/generate-routes.tsx
CHANGED
|
@@ -33,19 +33,19 @@ const generateRoutes = async (
|
|
|
33
33
|
(route) => !!matchPath(route.path, options.pathname)
|
|
34
34
|
);
|
|
35
35
|
|
|
36
|
-
const preloadedElement = preload === undefined ? options.notFoundComp : preload.element
|
|
36
|
+
const preloadedElement = preload === undefined ? options.notFoundComp : preload.element;
|
|
37
37
|
|
|
38
38
|
// fallback to previous version
|
|
39
39
|
const preloadedComp: any = typeof preloadedElement === 'function' ?
|
|
40
40
|
await preloadedElement().props.mod
|
|
41
41
|
:
|
|
42
|
-
await preloadedElement.props.mod
|
|
42
|
+
await preloadedElement.props.mod;
|
|
43
43
|
|
|
44
44
|
const renderElement = (path: string, bundle: ReactElement) => {
|
|
45
45
|
if (!preloadedComp) return bundle;
|
|
46
46
|
const isRouteMatched = (preload && preload.path === path) || (!preload && !path);
|
|
47
47
|
const Element = isRouteMatched ? preloadedComp.default : bundle;
|
|
48
|
-
return isRouteMatched ? <Element /> : Element
|
|
48
|
+
return isRouteMatched ? <Element /> : Element;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
return (
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Bundle from './bundle'
|
|
2
|
-
import generateRoutes from './generate-routes'
|
|
1
|
+
import Bundle from './bundle';
|
|
2
|
+
import generateRoutes from './generate-routes';
|
|
3
3
|
|
|
4
|
-
export { Bundle, generateRoutes }
|
|
4
|
+
export { Bundle, generateRoutes };
|
package/tsconfig.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"outDir": "
|
|
3
|
+
"outDir": "lib",
|
|
4
4
|
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
|
|
5
5
|
"module": "esnext" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
|
|
6
6
|
"lib": [
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
"allowJs": true /* Allow javascript files to be compiled. */,
|
|
11
11
|
"jsx": "react-jsx" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
|
|
12
12
|
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
|
|
13
|
-
"moduleResolution": "node"
|
|
13
|
+
"moduleResolution": "node",
|
|
14
14
|
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
|
|
15
15
|
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
|
16
|
-
"skipLibCheck": true
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"declaration": true
|
|
17
18
|
},
|
|
18
19
|
"include": ["src/**/*"],
|
|
19
20
|
"exclude": ["node_modules", "build", "scripts", "webpack", "jest"]
|