@modern-js/runtime 2.0.0-beta.2 → 2.0.0-canary.0
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/CHANGELOG.md +100 -0
- package/dist/js/modern/router/runtime/index.js +1 -0
- package/dist/js/modern/router/runtime/plugin.js +27 -7
- package/dist/js/modern/router/runtime/plugin.node.js +10 -6
- package/dist/js/modern/router/runtime/server.js +1 -0
- package/dist/js/modern/router/runtime/utils.js +2 -4
- package/dist/js/modern/ssr/cli/index.js +14 -0
- package/dist/js/modern/ssr/serverRender/renderToStream/bulidTemplate.before.js +13 -6
- package/dist/js/modern/state/runtime/plugin.js +10 -3
- package/dist/js/node/router/runtime/index.js +9 -1
- package/dist/js/node/router/runtime/plugin.js +30 -6
- package/dist/js/node/router/runtime/plugin.node.js +9 -5
- package/dist/js/node/router/runtime/server.js +16 -0
- package/dist/js/node/router/runtime/utils.js +2 -4
- package/dist/js/node/ssr/cli/index.js +14 -0
- package/dist/js/node/ssr/serverRender/renderToStream/bulidTemplate.before.js +13 -6
- package/dist/js/node/state/runtime/plugin.js +10 -3
- package/dist/js/treeshaking/router/runtime/index.js +1 -0
- package/dist/js/treeshaking/router/runtime/plugin.js +27 -7
- package/dist/js/treeshaking/router/runtime/plugin.node.js +18 -13
- package/dist/js/treeshaking/router/runtime/server.js +1 -0
- package/dist/js/treeshaking/router/runtime/utils.js +2 -4
- package/dist/js/treeshaking/ssr/cli/index.js +15 -0
- package/dist/js/treeshaking/ssr/serverRender/renderToStream/bulidTemplate.before.js +14 -7
- package/dist/js/treeshaking/state/runtime/plugin.js +14 -3
- package/dist/types/router/runtime/index.d.ts +1 -0
- package/dist/types/router/runtime/plugin.d.ts +5 -1
- package/dist/types/router/runtime/plugin.node.d.ts +1 -0
- package/dist/types/router/runtime/server.d.ts +1 -0
- package/dist/types/router/runtime/types.d.ts +3 -1
- package/dist/types/state/runtime/plugin.d.ts +7 -2
- package/package.json +32 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,105 @@
|
|
|
1
1
|
# @modern-js/runtime
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.3
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9c3e: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- c9e800d39a: feat: support React18 streaming SSR
|
|
12
|
+
feat: 支持 React18 流式 SSR
|
|
13
|
+
- 543be9558e: feat: compile server loader and support handle loader request
|
|
14
|
+
feat: 编译 server loader 并支持处理 loader 的请求
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 2344eb26ed: fix: bootstrap function params type define
|
|
19
|
+
|
|
20
|
+
fix: 修复 bootstrap 函数参数类型定义
|
|
21
|
+
|
|
22
|
+
- a11fcf8b50: feat: fallback logic of streaming ssr
|
|
23
|
+
feat: streaming ssr 降级逻辑
|
|
24
|
+
- e7ce063: fix: root layout css chunks should't be loaded
|
|
25
|
+
fix: 不应该加载 root layout 的 css chunks
|
|
26
|
+
- b18fa8f3ed: feat: remove @loadable/component in streaming ssr
|
|
27
|
+
feat: 移除 streaming ssr 中的 @loadable/component 逻辑
|
|
28
|
+
- 6604f1b: feat: support router basename
|
|
29
|
+
feat: router 插件支持设置 basename
|
|
30
|
+
- fda836f: feat: support `models`,`initialState` config for state plugin
|
|
31
|
+
feat: state 插件支持`model`,`initialState` 配置
|
|
32
|
+
- 3e57f2bd58: feat: add document feature with plugin
|
|
33
|
+
|
|
34
|
+
feat: 增加 document 功能插件
|
|
35
|
+
|
|
36
|
+
- 2e60319: fix: some optimizations for router and loader
|
|
37
|
+
fix: 一些 router 和 loader 的优化
|
|
38
|
+
q
|
|
39
|
+
- fbf5eed5aa: fix: fix ssg failure due to lack of Web Response API
|
|
40
|
+
fix: 修复因为缺少 Web Response API 而导致 ssg 失败
|
|
41
|
+
- a2509bfbdb: feat: bump esbuild from 0.14.38 to 0.15.7
|
|
42
|
+
|
|
43
|
+
feat: 将 esbuild 从 0.14.38 版本升级至 0.15.7 版本
|
|
44
|
+
|
|
45
|
+
- 425e570: feat: export react-router-dom/server staticRouter
|
|
46
|
+
feat: 导出 react-router-dom/server 的 staticRouter 组件
|
|
47
|
+
- e4357f1: fix: change default document file and name
|
|
48
|
+
|
|
49
|
+
fix: 重置默认的 document 文件和文件名
|
|
50
|
+
|
|
51
|
+
- 4369648ae2: fix: fix html template of streaming ssr
|
|
52
|
+
fix: 修复流式渲染的 html 模版
|
|
53
|
+
- 92c0994468: chore: remove `registerPrefetch`
|
|
54
|
+
chore: 移除 `registerPrefetch`
|
|
55
|
+
- 6bda14ed71: feat: refactor router with react-router@6.4
|
|
56
|
+
|
|
57
|
+
feat: 使用 react-router@6.4 重构路由模块
|
|
58
|
+
|
|
59
|
+
- 92004d1906: feat: support load chunks parallelly
|
|
60
|
+
feat: 支持并行加载 chunks
|
|
61
|
+
- 40ed5874c6: feat: inject css chunk into html for streaming ssr
|
|
62
|
+
feat: streaming ssr 返回的 html 注入 css chunk
|
|
63
|
+
- 60d5378632: fix: function extname should not return array
|
|
64
|
+
fix: 函数 extname 不应该返回一个数组
|
|
65
|
+
- 8b8e1bb571: feat: support nested routes
|
|
66
|
+
feat: 支持嵌套路由
|
|
67
|
+
- 3bbea92b2a: feat: support Hook、Middleware new API
|
|
68
|
+
feat: 支持 Hook、Middleware 的新 API
|
|
69
|
+
- 18aaf42249: fix: fix server loader redirects
|
|
70
|
+
fix: 修复 server loader 重定向错误
|
|
71
|
+
- 34702d5: feat: support internal env vars: metaName_TARGET
|
|
72
|
+
feat: 支持内置环境变量 metaName_TARGET
|
|
73
|
+
- fcace5b5b9: fix: remove overmuch `@modernjs/utils` dependency import in ssr runtime & SSR hydrate error
|
|
74
|
+
fix: 去除 ssr 运行时过多的 `@modernjs/utils` 依赖引入 & SSR hydrate 错误
|
|
75
|
+
- Updated dependencies [6aca875]
|
|
76
|
+
- Updated dependencies [2e60319]
|
|
77
|
+
- Updated dependencies [92f0eade39]
|
|
78
|
+
- Updated dependencies [edd1cfb1af]
|
|
79
|
+
- Updated dependencies [cc971eabfc]
|
|
80
|
+
- Updated dependencies [5b9049f2e9]
|
|
81
|
+
- Updated dependencies [6bda14ed71]
|
|
82
|
+
- Updated dependencies [92004d1906]
|
|
83
|
+
- Updated dependencies [b8bbe036c7]
|
|
84
|
+
- Updated dependencies [40ed5874c6]
|
|
85
|
+
- Updated dependencies [87c1ff86b9]
|
|
86
|
+
- Updated dependencies [d5a31df781]
|
|
87
|
+
- Updated dependencies [dda38c9c3e]
|
|
88
|
+
- Updated dependencies [102d32e4ba]
|
|
89
|
+
- Updated dependencies [8b8e1bb571]
|
|
90
|
+
- Updated dependencies [3bbea92b2a]
|
|
91
|
+
- Updated dependencies [b710adb]
|
|
92
|
+
- Updated dependencies [f179749375]
|
|
93
|
+
- Updated dependencies [ea7cf06]
|
|
94
|
+
- Updated dependencies [bbe4c4a]
|
|
95
|
+
- Updated dependencies [e4558a0]
|
|
96
|
+
- Updated dependencies [abf3421a75]
|
|
97
|
+
- Updated dependencies [543be9558e]
|
|
98
|
+
- Updated dependencies [14b712da84]
|
|
99
|
+
- @modern-js/utils@2.0.0-beta.3
|
|
100
|
+
- @modern-js/types@2.0.0-beta.3
|
|
101
|
+
- @modern-js/plugin@2.0.0-beta.3
|
|
102
|
+
|
|
3
103
|
## 2.0.0-beta.2
|
|
4
104
|
|
|
5
105
|
### Major Changes
|
|
@@ -4,15 +4,34 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements } from 'react-router-dom';
|
|
6
6
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
7
|
-
import { renderRoutes } from "./utils";
|
|
7
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
8
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
10
|
+
export let finalRouteConfig = {
|
|
11
|
+
routes: []
|
|
12
|
+
};
|
|
13
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
14
|
+
export let beforeRenderRouter = true;
|
|
15
|
+
export function modifyRoutes(modifyFunction) {
|
|
16
|
+
if (beforeRenderRouter) {
|
|
17
|
+
const {
|
|
18
|
+
routes: originRoutes
|
|
19
|
+
} = finalRouteConfig;
|
|
20
|
+
const newRoutes = modifyFunction(originRoutes);
|
|
21
|
+
finalRouteConfig.routes = newRoutes;
|
|
22
|
+
} else {
|
|
23
|
+
console.error('it is not allowed to modify routes config after router render.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
9
26
|
export const routerPlugin = ({
|
|
10
27
|
serverBase: _serverBase = [],
|
|
11
28
|
supportHtml5History: _supportHtml5History = true,
|
|
29
|
+
basename: _basename2 = '',
|
|
12
30
|
routesConfig,
|
|
13
31
|
createRoutes
|
|
14
32
|
}) => {
|
|
15
33
|
const select = pathname => _serverBase.find(baseUrl => pathname.search(baseUrl) === 0) || '/';
|
|
34
|
+
finalRouteConfig = routesConfig;
|
|
16
35
|
return {
|
|
17
36
|
name: '@modern-js/plugin-router',
|
|
18
37
|
setup: () => {
|
|
@@ -22,7 +41,7 @@ export const routerPlugin = ({
|
|
|
22
41
|
}, next) => {
|
|
23
42
|
// can not get routes config, skip wrapping React Router.
|
|
24
43
|
// e.g. App.tsx as the entrypoint
|
|
25
|
-
if (!
|
|
44
|
+
if (!finalRouteConfig && !createRoutes) {
|
|
26
45
|
return next({
|
|
27
46
|
App
|
|
28
47
|
});
|
|
@@ -30,13 +49,14 @@ export const routerPlugin = ({
|
|
|
30
49
|
const getRouteApp = () => {
|
|
31
50
|
return props => {
|
|
32
51
|
var _window$_SERVER_DATA;
|
|
33
|
-
|
|
34
|
-
const routes = createRoutes ? createRoutes() : createRoutesFromElements(
|
|
52
|
+
beforeRenderRouter = true;
|
|
53
|
+
const routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(finalRouteConfig));
|
|
35
54
|
const baseUrl = ((_window$_SERVER_DATA = window._SERVER_DATA) === null || _window$_SERVER_DATA === void 0 ? void 0 : _window$_SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
55
|
+
const _basename = baseUrl === '/' ? urlJoin(baseUrl, _basename2) : baseUrl;
|
|
36
56
|
const router = _supportHtml5History ? createBrowserRouter(routes, {
|
|
37
|
-
basename:
|
|
57
|
+
basename: _basename
|
|
38
58
|
}) : createHashRouter(routes, {
|
|
39
|
-
basename:
|
|
59
|
+
basename: _basename
|
|
40
60
|
});
|
|
41
61
|
return /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, props), {}, {
|
|
42
62
|
children: /*#__PURE__*/_jsx(RouterProvider, {
|
|
@@ -46,7 +66,7 @@ export const routerPlugin = ({
|
|
|
46
66
|
};
|
|
47
67
|
};
|
|
48
68
|
const RouteApp = getRouteApp();
|
|
49
|
-
if (routesConfig.globalApp) {
|
|
69
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
50
70
|
return next({
|
|
51
71
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
52
72
|
});
|
|
@@ -8,7 +8,7 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
8
8
|
import { installGlobals } from '@remix-run/node';
|
|
9
9
|
import { createRoutesFromElements } from 'react-router-dom';
|
|
10
10
|
import { RuntimeReactContext } from "../../core";
|
|
11
|
-
import { renderRoutes } from "./utils";
|
|
11
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
12
12
|
|
|
13
13
|
// Polyfill Web Fetch API
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -54,6 +54,7 @@ export function createFetchHeaders(requestHeaders) {
|
|
|
54
54
|
return headers;
|
|
55
55
|
}
|
|
56
56
|
export const routerPlugin = ({
|
|
57
|
+
basename: _basename2 = '',
|
|
57
58
|
routesConfig,
|
|
58
59
|
createRoutes
|
|
59
60
|
}) => {
|
|
@@ -66,7 +67,7 @@ export const routerPlugin = ({
|
|
|
66
67
|
}, next) {
|
|
67
68
|
// can not get routes config, skip wrapping React Router.
|
|
68
69
|
// e.g. App.tsx as the entrypoint
|
|
69
|
-
if (!routesConfig) {
|
|
70
|
+
if (!routesConfig && !createRoutes) {
|
|
70
71
|
return next({
|
|
71
72
|
context
|
|
72
73
|
});
|
|
@@ -74,11 +75,14 @@ export const routerPlugin = ({
|
|
|
74
75
|
const {
|
|
75
76
|
request
|
|
76
77
|
} = context.ssrContext;
|
|
77
|
-
const
|
|
78
|
-
const
|
|
78
|
+
const baseUrl = request.baseUrl;
|
|
79
|
+
const _basename = baseUrl === '/' ? urlJoin(baseUrl, _basename2) : baseUrl;
|
|
80
|
+
const routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(routesConfig));
|
|
79
81
|
const {
|
|
80
82
|
query
|
|
81
|
-
} = createStaticHandler(routes
|
|
83
|
+
} = createStaticHandler(routes, {
|
|
84
|
+
basename: _basename
|
|
85
|
+
});
|
|
82
86
|
const remixRequest = createFetchRequest(request);
|
|
83
87
|
const routerContext = await query(remixRequest);
|
|
84
88
|
if (routerContext instanceof Response) {
|
|
@@ -122,7 +126,7 @@ export const routerPlugin = ({
|
|
|
122
126
|
};
|
|
123
127
|
};
|
|
124
128
|
const RouteApp = getRouteApp();
|
|
125
|
-
if (routesConfig.globalApp) {
|
|
129
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
126
130
|
return next({
|
|
127
131
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
128
132
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-router-dom/server';
|
|
@@ -49,12 +49,10 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
|
-
if (!parent) {
|
|
52
|
+
if (!parent && element) {
|
|
53
53
|
element = /*#__PURE__*/_jsx(RootLayout, {
|
|
54
54
|
routes: [nestedRoute],
|
|
55
|
-
children:
|
|
56
|
-
children: element
|
|
57
|
-
})
|
|
55
|
+
children: element
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
58
|
routeProps.element = element;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1
4
|
import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSingleEntry } from '@modern-js/utils';
|
|
2
5
|
const PLUGIN_IDENTIFIER = 'ssr';
|
|
3
6
|
const hasStringSSREntry = userConfig => {
|
|
@@ -36,6 +39,7 @@ export default (() => ({
|
|
|
36
39
|
tools: {
|
|
37
40
|
webpackChain: (chain, {
|
|
38
41
|
name,
|
|
42
|
+
isServer,
|
|
39
43
|
CHAIN_ID
|
|
40
44
|
}) => {
|
|
41
45
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -46,6 +50,16 @@ export default (() => ({
|
|
|
46
50
|
filename: LOADABLE_STATS_FILE
|
|
47
51
|
}]);
|
|
48
52
|
}
|
|
53
|
+
|
|
54
|
+
// add environment variables to determine the node/browser
|
|
55
|
+
const prefix = `${appContext.metaName.split(/[-_]/)[0]}_`.toUpperCase();
|
|
56
|
+
const modernVars = {
|
|
57
|
+
[`process.env.${prefix}TARGET`]: JSON.stringify(isServer ? 'node' : 'browser')
|
|
58
|
+
};
|
|
59
|
+
chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(args => {
|
|
60
|
+
const [vars, ...rest] = args;
|
|
61
|
+
return [_objectSpread(_objectSpread({}, vars), modernVars), ...rest];
|
|
62
|
+
});
|
|
49
63
|
},
|
|
50
64
|
babel: config => {
|
|
51
65
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -33,14 +33,21 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
33
33
|
} = routeManifest;
|
|
34
34
|
const cssChunks = [];
|
|
35
35
|
const matches = matchRoutes(routes, routerContext.location);
|
|
36
|
-
matches === null || matches === void 0 ? void 0 : matches.forEach(match => {
|
|
36
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach((match, index) => {
|
|
37
|
+
// root layout css chunks should't be loaded
|
|
38
|
+
if (!index) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
37
41
|
const routeId = match.route.id;
|
|
38
42
|
if (routeId) {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
const routeManifest = routeAssets[routeId];
|
|
44
|
+
if (routeManifest) {
|
|
45
|
+
const {
|
|
46
|
+
assets = []
|
|
47
|
+
} = routeManifest;
|
|
48
|
+
const _cssChunks = assets.filter(asset => asset === null || asset === void 0 ? void 0 : asset.endsWith('.css'));
|
|
49
|
+
cssChunks.push(..._cssChunks);
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
});
|
|
46
53
|
const styleLinks = cssChunks.map(chunk => {
|
|
@@ -19,9 +19,16 @@ const getStoreConfig = config => {
|
|
|
19
19
|
const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
20
20
|
const plugins = [];
|
|
21
21
|
internalPlugins.filter(plugin => config[plugin] !== false).forEach(plugin => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const storeConfig = {};
|
|
23
|
+
for (const [key, value] of Object.entries(config)) {
|
|
24
|
+
if (internalPlugins.includes(key)) {
|
|
25
|
+
plugins.push(StatePluginHandleMap[key](value));
|
|
26
|
+
} else {
|
|
27
|
+
storeConfig[key] = value;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
storeConfig.plugins = plugins;
|
|
31
|
+
return storeConfig;
|
|
25
32
|
};
|
|
26
33
|
const state = config => ({
|
|
27
34
|
name: '@modern-js/plugin-state',
|
|
@@ -3,8 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
modifyRoutes: true
|
|
8
|
+
};
|
|
7
9
|
exports.default = void 0;
|
|
10
|
+
Object.defineProperty(exports, "modifyRoutes", {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _plugin.modifyRoutes;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
8
16
|
var _plugin = require("./plugin");
|
|
9
17
|
var _reactRouterDom = require("react-router-dom");
|
|
10
18
|
Object.keys(_reactRouterDom).forEach(function (key) {
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.finalRouteConfig = exports.beforeRenderRouter = void 0;
|
|
7
|
+
exports.modifyRoutes = modifyRoutes;
|
|
6
8
|
exports.routerPlugin = void 0;
|
|
7
9
|
var _react = _interopRequireDefault(require("react"));
|
|
8
10
|
var _reactRouterDom = require("react-router-dom");
|
|
@@ -13,13 +15,34 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
13
15
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
17
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
19
|
+
let finalRouteConfig = {
|
|
20
|
+
routes: []
|
|
21
|
+
};
|
|
22
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
23
|
+
exports.finalRouteConfig = finalRouteConfig;
|
|
24
|
+
let beforeRenderRouter = true;
|
|
25
|
+
exports.beforeRenderRouter = beforeRenderRouter;
|
|
26
|
+
function modifyRoutes(modifyFunction) {
|
|
27
|
+
if (beforeRenderRouter) {
|
|
28
|
+
const {
|
|
29
|
+
routes: originRoutes
|
|
30
|
+
} = finalRouteConfig;
|
|
31
|
+
const newRoutes = modifyFunction(originRoutes);
|
|
32
|
+
finalRouteConfig.routes = newRoutes;
|
|
33
|
+
} else {
|
|
34
|
+
console.error('it is not allowed to modify routes config after router render.');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
16
37
|
const routerPlugin = ({
|
|
17
38
|
serverBase: _serverBase = [],
|
|
18
39
|
supportHtml5History: _supportHtml5History = true,
|
|
40
|
+
basename: _basename2 = '',
|
|
19
41
|
routesConfig,
|
|
20
42
|
createRoutes
|
|
21
43
|
}) => {
|
|
22
44
|
const select = pathname => _serverBase.find(baseUrl => pathname.search(baseUrl) === 0) || '/';
|
|
45
|
+
exports.finalRouteConfig = finalRouteConfig = routesConfig;
|
|
23
46
|
return {
|
|
24
47
|
name: '@modern-js/plugin-router',
|
|
25
48
|
setup: () => {
|
|
@@ -29,7 +52,7 @@ const routerPlugin = ({
|
|
|
29
52
|
}, next) => {
|
|
30
53
|
// can not get routes config, skip wrapping React Router.
|
|
31
54
|
// e.g. App.tsx as the entrypoint
|
|
32
|
-
if (!
|
|
55
|
+
if (!finalRouteConfig && !createRoutes) {
|
|
33
56
|
return next({
|
|
34
57
|
App
|
|
35
58
|
});
|
|
@@ -37,13 +60,14 @@ const routerPlugin = ({
|
|
|
37
60
|
const getRouteApp = () => {
|
|
38
61
|
return props => {
|
|
39
62
|
var _window$_SERVER_DATA;
|
|
40
|
-
|
|
41
|
-
const routes = createRoutes ? createRoutes() : (0, _reactRouterDom.createRoutesFromElements)(
|
|
63
|
+
exports.beforeRenderRouter = beforeRenderRouter = true;
|
|
64
|
+
const routes = createRoutes ? createRoutes() : (0, _reactRouterDom.createRoutesFromElements)((0, _utils.renderRoutes)(finalRouteConfig));
|
|
42
65
|
const baseUrl = ((_window$_SERVER_DATA = window._SERVER_DATA) === null || _window$_SERVER_DATA === void 0 ? void 0 : _window$_SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
66
|
+
const _basename = baseUrl === '/' ? (0, _utils.urlJoin)(baseUrl, _basename2) : baseUrl;
|
|
43
67
|
const router = _supportHtml5History ? (0, _reactRouterDom.createBrowserRouter)(routes, {
|
|
44
|
-
basename:
|
|
68
|
+
basename: _basename
|
|
45
69
|
}) : (0, _reactRouterDom.createHashRouter)(routes, {
|
|
46
|
-
basename:
|
|
70
|
+
basename: _basename
|
|
47
71
|
});
|
|
48
72
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread(_objectSpread({}, props), {}, {
|
|
49
73
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.RouterProvider, {
|
|
@@ -53,7 +77,7 @@ const routerPlugin = ({
|
|
|
53
77
|
};
|
|
54
78
|
};
|
|
55
79
|
const RouteApp = getRouteApp();
|
|
56
|
-
if (routesConfig.globalApp) {
|
|
80
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
57
81
|
return next({
|
|
58
82
|
App: (0, _hoistNonReactStatics.default)(RouteApp, routesConfig.globalApp)
|
|
59
83
|
});
|
|
@@ -63,6 +63,7 @@ function createFetchHeaders(requestHeaders) {
|
|
|
63
63
|
return headers;
|
|
64
64
|
}
|
|
65
65
|
const routerPlugin = ({
|
|
66
|
+
basename: _basename2 = '',
|
|
66
67
|
routesConfig,
|
|
67
68
|
createRoutes
|
|
68
69
|
}) => {
|
|
@@ -75,7 +76,7 @@ const routerPlugin = ({
|
|
|
75
76
|
}, next) {
|
|
76
77
|
// can not get routes config, skip wrapping React Router.
|
|
77
78
|
// e.g. App.tsx as the entrypoint
|
|
78
|
-
if (!routesConfig) {
|
|
79
|
+
if (!routesConfig && !createRoutes) {
|
|
79
80
|
return next({
|
|
80
81
|
context
|
|
81
82
|
});
|
|
@@ -83,11 +84,14 @@ const routerPlugin = ({
|
|
|
83
84
|
const {
|
|
84
85
|
request
|
|
85
86
|
} = context.ssrContext;
|
|
86
|
-
const
|
|
87
|
-
const
|
|
87
|
+
const baseUrl = request.baseUrl;
|
|
88
|
+
const _basename = baseUrl === '/' ? (0, _utils.urlJoin)(baseUrl, _basename2) : baseUrl;
|
|
89
|
+
const routes = createRoutes ? createRoutes() : (0, _reactRouterDom.createRoutesFromElements)((0, _utils.renderRoutes)(routesConfig));
|
|
88
90
|
const {
|
|
89
91
|
query
|
|
90
|
-
} = (0, _router.unstable_createStaticHandler)(routes
|
|
92
|
+
} = (0, _router.unstable_createStaticHandler)(routes, {
|
|
93
|
+
basename: _basename
|
|
94
|
+
});
|
|
91
95
|
const remixRequest = createFetchRequest(request);
|
|
92
96
|
const routerContext = await query(remixRequest);
|
|
93
97
|
if (routerContext instanceof Response) {
|
|
@@ -131,7 +135,7 @@ const routerPlugin = ({
|
|
|
131
135
|
};
|
|
132
136
|
};
|
|
133
137
|
const RouteApp = getRouteApp();
|
|
134
|
-
if (routesConfig.globalApp) {
|
|
138
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
135
139
|
return next({
|
|
136
140
|
App: (0, _hoistNonReactStatics.default)(RouteApp, routesConfig.globalApp)
|
|
137
141
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _server = require("react-router-dom/server");
|
|
7
|
+
Object.keys(_server).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _server[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _server[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -61,12 +61,10 @@ const renderNestedRoute = (nestedRoute, parent) => {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
if (!parent) {
|
|
64
|
+
if (!parent && element) {
|
|
65
65
|
element = /*#__PURE__*/(0, _jsxRuntime.jsx)(_root.RootLayout, {
|
|
66
66
|
routes: [nestedRoute],
|
|
67
|
-
children:
|
|
68
|
-
children: element
|
|
69
|
-
})
|
|
67
|
+
children: element
|
|
70
68
|
});
|
|
71
69
|
}
|
|
72
70
|
routeProps.element = element;
|
|
@@ -5,6 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _utils = require("@modern-js/utils");
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
11
|
const PLUGIN_IDENTIFIER = 'ssr';
|
|
9
12
|
const hasStringSSREntry = userConfig => {
|
|
10
13
|
const isStreaming = ssr => ssr && typeof ssr === 'object' && ssr.mode === 'stream';
|
|
@@ -42,6 +45,7 @@ var _default = () => ({
|
|
|
42
45
|
tools: {
|
|
43
46
|
webpackChain: (chain, {
|
|
44
47
|
name,
|
|
48
|
+
isServer,
|
|
45
49
|
CHAIN_ID
|
|
46
50
|
}) => {
|
|
47
51
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -52,6 +56,16 @@ var _default = () => ({
|
|
|
52
56
|
filename: _utils.LOADABLE_STATS_FILE
|
|
53
57
|
}]);
|
|
54
58
|
}
|
|
59
|
+
|
|
60
|
+
// add environment variables to determine the node/browser
|
|
61
|
+
const prefix = `${appContext.metaName.split(/[-_]/)[0]}_`.toUpperCase();
|
|
62
|
+
const modernVars = {
|
|
63
|
+
[`process.env.${prefix}TARGET`]: JSON.stringify(isServer ? 'node' : 'browser')
|
|
64
|
+
};
|
|
65
|
+
chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(args => {
|
|
66
|
+
const [vars, ...rest] = args;
|
|
67
|
+
return [_objectSpread(_objectSpread({}, vars), modernVars), ...rest];
|
|
68
|
+
});
|
|
55
69
|
},
|
|
56
70
|
babel: config => {
|
|
57
71
|
const userConfig = api.useResolvedConfigContext();
|
|
@@ -40,14 +40,21 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
40
40
|
} = routeManifest;
|
|
41
41
|
const cssChunks = [];
|
|
42
42
|
const matches = (0, _reactRouterDom.matchRoutes)(routes, routerContext.location);
|
|
43
|
-
matches === null || matches === void 0 ? void 0 : matches.forEach(match => {
|
|
43
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach((match, index) => {
|
|
44
|
+
// root layout css chunks should't be loaded
|
|
45
|
+
if (!index) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
44
48
|
const routeId = match.route.id;
|
|
45
49
|
if (routeId) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const routeManifest = routeAssets[routeId];
|
|
51
|
+
if (routeManifest) {
|
|
52
|
+
const {
|
|
53
|
+
assets = []
|
|
54
|
+
} = routeManifest;
|
|
55
|
+
const _cssChunks = assets.filter(asset => asset === null || asset === void 0 ? void 0 : asset.endsWith('.css'));
|
|
56
|
+
cssChunks.push(..._cssChunks);
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
});
|
|
53
60
|
const styleLinks = cssChunks.map(chunk => {
|
|
@@ -38,9 +38,16 @@ const getStoreConfig = config => {
|
|
|
38
38
|
const internalPlugins = ['immer', 'effects', 'autoActions', 'devtools'];
|
|
39
39
|
const plugins = [];
|
|
40
40
|
internalPlugins.filter(plugin => config[plugin] !== false).forEach(plugin => plugins.push(StatePluginHandleMap[plugin](config[plugin])));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const storeConfig = {};
|
|
42
|
+
for (const [key, value] of Object.entries(config)) {
|
|
43
|
+
if (internalPlugins.includes(key)) {
|
|
44
|
+
plugins.push(StatePluginHandleMap[key](value));
|
|
45
|
+
} else {
|
|
46
|
+
storeConfig[key] = value;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
storeConfig.plugins = plugins;
|
|
50
|
+
return storeConfig;
|
|
44
51
|
};
|
|
45
52
|
const state = config => ({
|
|
46
53
|
name: '@modern-js/plugin-state',
|
|
@@ -2,13 +2,31 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { createBrowserRouter, createHashRouter, RouterProvider, createRoutesFromElements } from 'react-router-dom';
|
|
4
4
|
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
5
|
-
import { renderRoutes } from "./utils";
|
|
5
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
8
|
+
export var finalRouteConfig = {
|
|
9
|
+
routes: []
|
|
10
|
+
};
|
|
11
|
+
// eslint-disable-next-line import/no-mutable-exports
|
|
12
|
+
export var beforeRenderRouter = true;
|
|
13
|
+
export function modifyRoutes(modifyFunction) {
|
|
14
|
+
if (beforeRenderRouter) {
|
|
15
|
+
var _finalRouteConfig = finalRouteConfig,
|
|
16
|
+
originRoutes = _finalRouteConfig.routes;
|
|
17
|
+
var newRoutes = modifyFunction(originRoutes);
|
|
18
|
+
finalRouteConfig.routes = newRoutes;
|
|
19
|
+
} else {
|
|
20
|
+
console.error('it is not allowed to modify routes config after router render.');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
7
23
|
export var routerPlugin = function routerPlugin(_ref) {
|
|
8
24
|
var _ref$serverBase = _ref.serverBase,
|
|
9
25
|
serverBase = _ref$serverBase === void 0 ? [] : _ref$serverBase,
|
|
10
26
|
_ref$supportHtml5Hist = _ref.supportHtml5History,
|
|
11
27
|
supportHtml5History = _ref$supportHtml5Hist === void 0 ? true : _ref$supportHtml5Hist,
|
|
28
|
+
_ref$basename = _ref.basename,
|
|
29
|
+
basename = _ref$basename === void 0 ? '' : _ref$basename,
|
|
12
30
|
routesConfig = _ref.routesConfig,
|
|
13
31
|
createRoutes = _ref.createRoutes;
|
|
14
32
|
var select = function select(pathname) {
|
|
@@ -16,6 +34,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
16
34
|
return pathname.search(baseUrl) === 0;
|
|
17
35
|
}) || '/';
|
|
18
36
|
};
|
|
37
|
+
finalRouteConfig = routesConfig;
|
|
19
38
|
return {
|
|
20
39
|
name: '@modern-js/plugin-router',
|
|
21
40
|
setup: function setup() {
|
|
@@ -24,7 +43,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
24
43
|
var App = _ref2.App;
|
|
25
44
|
// can not get routes config, skip wrapping React Router.
|
|
26
45
|
// e.g. App.tsx as the entrypoint
|
|
27
|
-
if (!
|
|
46
|
+
if (!finalRouteConfig && !createRoutes) {
|
|
28
47
|
return next({
|
|
29
48
|
App: App
|
|
30
49
|
});
|
|
@@ -32,13 +51,14 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
32
51
|
var getRouteApp = function getRouteApp() {
|
|
33
52
|
return function (props) {
|
|
34
53
|
var _window$_SERVER_DATA;
|
|
35
|
-
|
|
36
|
-
var routes = createRoutes ? createRoutes() : createRoutesFromElements(
|
|
54
|
+
beforeRenderRouter = true;
|
|
55
|
+
var routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(finalRouteConfig));
|
|
37
56
|
var baseUrl = ((_window$_SERVER_DATA = window._SERVER_DATA) === null || _window$_SERVER_DATA === void 0 ? void 0 : _window$_SERVER_DATA.router.baseUrl) || select(location.pathname);
|
|
57
|
+
var _basename = baseUrl === '/' ? urlJoin(baseUrl, basename) : baseUrl;
|
|
38
58
|
var router = supportHtml5History ? createBrowserRouter(routes, {
|
|
39
|
-
basename:
|
|
59
|
+
basename: _basename
|
|
40
60
|
}) : createHashRouter(routes, {
|
|
41
|
-
basename:
|
|
61
|
+
basename: _basename
|
|
42
62
|
});
|
|
43
63
|
return /*#__PURE__*/_jsx(App, _objectSpread(_objectSpread({}, props), {}, {
|
|
44
64
|
children: /*#__PURE__*/_jsx(RouterProvider, {
|
|
@@ -48,7 +68,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
48
68
|
};
|
|
49
69
|
};
|
|
50
70
|
var RouteApp = getRouteApp();
|
|
51
|
-
if (routesConfig.globalApp) {
|
|
71
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
52
72
|
return next({
|
|
53
73
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
54
74
|
});
|
|
@@ -10,7 +10,7 @@ import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
|
10
10
|
import { installGlobals } from '@remix-run/node';
|
|
11
11
|
import { createRoutesFromElements } from 'react-router-dom';
|
|
12
12
|
import { RuntimeReactContext } from "../../core";
|
|
13
|
-
import { renderRoutes } from "./utils";
|
|
13
|
+
import { renderRoutes, urlJoin } from "./utils";
|
|
14
14
|
|
|
15
15
|
// Polyfill Web Fetch API
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -68,7 +68,9 @@ export function createFetchHeaders(requestHeaders) {
|
|
|
68
68
|
return headers;
|
|
69
69
|
}
|
|
70
70
|
export var routerPlugin = function routerPlugin(_ref) {
|
|
71
|
-
var
|
|
71
|
+
var _ref$basename = _ref.basename,
|
|
72
|
+
basename = _ref$basename === void 0 ? '' : _ref$basename,
|
|
73
|
+
routesConfig = _ref.routesConfig,
|
|
72
74
|
createRoutes = _ref.createRoutes;
|
|
73
75
|
return {
|
|
74
76
|
name: '@modern-js/plugin-router',
|
|
@@ -76,13 +78,13 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
76
78
|
return {
|
|
77
79
|
init: function init(_ref2, next) {
|
|
78
80
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
79
|
-
var context, _ref3, request,
|
|
81
|
+
var context, _ref3, request, baseUrl, _basename, routes, _createStaticHandler, query, remixRequest, routerContext, router;
|
|
80
82
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
81
83
|
while (1) {
|
|
82
84
|
switch (_context.prev = _context.next) {
|
|
83
85
|
case 0:
|
|
84
86
|
context = _ref2.context;
|
|
85
|
-
if (routesConfig) {
|
|
87
|
+
if (!(!routesConfig && !createRoutes)) {
|
|
86
88
|
_context.next = 3;
|
|
87
89
|
break;
|
|
88
90
|
}
|
|
@@ -91,20 +93,23 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
91
93
|
}));
|
|
92
94
|
case 3:
|
|
93
95
|
_ref3 = context.ssrContext, request = _ref3.request;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
baseUrl = request.baseUrl;
|
|
97
|
+
_basename = baseUrl === '/' ? urlJoin(baseUrl, basename) : baseUrl;
|
|
98
|
+
routes = createRoutes ? createRoutes() : createRoutesFromElements(renderRoutes(routesConfig));
|
|
99
|
+
_createStaticHandler = createStaticHandler(routes, {
|
|
100
|
+
basename: _basename
|
|
101
|
+
}), query = _createStaticHandler.query;
|
|
97
102
|
remixRequest = createFetchRequest(request);
|
|
98
|
-
_context.next =
|
|
103
|
+
_context.next = 11;
|
|
99
104
|
return query(remixRequest);
|
|
100
|
-
case
|
|
105
|
+
case 11:
|
|
101
106
|
routerContext = _context.sent;
|
|
102
107
|
if (!(routerContext instanceof Response)) {
|
|
103
|
-
_context.next =
|
|
108
|
+
_context.next = 14;
|
|
104
109
|
break;
|
|
105
110
|
}
|
|
106
111
|
return _context.abrupt("return", routerContext);
|
|
107
|
-
case
|
|
112
|
+
case 14:
|
|
108
113
|
router = createStaticRouter(routes, routerContext);
|
|
109
114
|
context.router = router;
|
|
110
115
|
context.routerContext = routerContext;
|
|
@@ -114,7 +119,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
114
119
|
return _context.abrupt("return", next({
|
|
115
120
|
context: context
|
|
116
121
|
}));
|
|
117
|
-
case
|
|
122
|
+
case 20:
|
|
118
123
|
case "end":
|
|
119
124
|
return _context.stop();
|
|
120
125
|
}
|
|
@@ -146,7 +151,7 @@ export var routerPlugin = function routerPlugin(_ref) {
|
|
|
146
151
|
};
|
|
147
152
|
};
|
|
148
153
|
var RouteApp = getRouteApp();
|
|
149
|
-
if (routesConfig.globalApp) {
|
|
154
|
+
if (routesConfig !== null && routesConfig !== void 0 && routesConfig.globalApp) {
|
|
150
155
|
return next({
|
|
151
156
|
App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
|
|
152
157
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-router-dom/server';
|
|
@@ -45,12 +45,10 @@ var renderNestedRoute = function renderNestedRoute(nestedRoute, parent) {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
if (!parent) {
|
|
48
|
+
if (!parent && element) {
|
|
49
49
|
element = /*#__PURE__*/_jsx(RootLayout, {
|
|
50
50
|
routes: [nestedRoute],
|
|
51
|
-
children:
|
|
52
|
-
children: element
|
|
53
|
-
})
|
|
51
|
+
children: element
|
|
54
52
|
});
|
|
55
53
|
}
|
|
56
54
|
routeProps.element = element;
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _toArray from "@babel/runtime/helpers/esm/toArray";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
1
5
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
6
|
import { getEntryOptions, SERVER_RENDER_FUNCTION_NAME, LOADABLE_STATS_FILE, isUseSSRBundle, createRuntimeExportsUtils, isSingleEntry } from '@modern-js/utils';
|
|
3
7
|
var PLUGIN_IDENTIFIER = 'ssr';
|
|
@@ -39,6 +43,7 @@ export default (function () {
|
|
|
39
43
|
tools: {
|
|
40
44
|
webpackChain: function webpackChain(chain, _ref) {
|
|
41
45
|
var name = _ref.name,
|
|
46
|
+
isServer = _ref.isServer,
|
|
42
47
|
CHAIN_ID = _ref.CHAIN_ID;
|
|
43
48
|
var userConfig = api.useResolvedConfigContext();
|
|
44
49
|
if (isUseSSRBundle(userConfig) && name !== 'server' && hasStringSSREntry(userConfig)) {
|
|
@@ -48,6 +53,16 @@ export default (function () {
|
|
|
48
53
|
filename: LOADABLE_STATS_FILE
|
|
49
54
|
}]);
|
|
50
55
|
}
|
|
56
|
+
|
|
57
|
+
// add environment variables to determine the node/browser
|
|
58
|
+
var prefix = "".concat(appContext.metaName.split(/[-_]/)[0], "_").toUpperCase();
|
|
59
|
+
var modernVars = _defineProperty({}, "process.env.".concat(prefix, "TARGET"), JSON.stringify(isServer ? 'node' : 'browser'));
|
|
60
|
+
chain.plugin(CHAIN_ID.PLUGIN.DEFINE).tap(function (args) {
|
|
61
|
+
var _args = _toArray(args),
|
|
62
|
+
vars = _args[0],
|
|
63
|
+
rest = _args.slice(1);
|
|
64
|
+
return [_objectSpread(_objectSpread({}, vars), modernVars)].concat(_toConsumableArray(rest));
|
|
65
|
+
});
|
|
51
66
|
},
|
|
52
67
|
babel: function babel(config) {
|
|
53
68
|
var userConfig = api.useResolvedConfigContext();
|
|
@@ -34,15 +34,22 @@ function getHeadTemplate(beforeEntryTemplate, context) {
|
|
|
34
34
|
var routeAssets = routeManifest.routeAssets;
|
|
35
35
|
var cssChunks = [];
|
|
36
36
|
var matches = matchRoutes(routes, routerContext.location);
|
|
37
|
-
matches === null || matches === void 0 ? void 0 : matches.forEach(function (match) {
|
|
37
|
+
matches === null || matches === void 0 ? void 0 : matches.forEach(function (match, index) {
|
|
38
|
+
// root layout css chunks should't be loaded
|
|
39
|
+
if (!index) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
38
42
|
var routeId = match.route.id;
|
|
39
43
|
if (routeId) {
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
var _routeManifest = routeAssets[routeId];
|
|
45
|
+
if (_routeManifest) {
|
|
46
|
+
var _routeManifest$assets = _routeManifest.assets,
|
|
47
|
+
assets = _routeManifest$assets === void 0 ? [] : _routeManifest$assets;
|
|
48
|
+
var _cssChunks = assets.filter(function (asset) {
|
|
49
|
+
return asset === null || asset === void 0 ? void 0 : asset.endsWith('.css');
|
|
50
|
+
});
|
|
51
|
+
cssChunks.push.apply(cssChunks, _toConsumableArray(_cssChunks));
|
|
52
|
+
}
|
|
46
53
|
}
|
|
47
54
|
});
|
|
48
55
|
var styleLinks = cssChunks.map(function (chunk) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
3
|
import { useContext } from 'react';
|
|
3
4
|
import { createStore } from '@modern-js-reduck/store';
|
|
4
5
|
import { Provider } from '@modern-js-reduck/react';
|
|
@@ -21,9 +22,19 @@ var getStoreConfig = function getStoreConfig(config) {
|
|
|
21
22
|
}).forEach(function (plugin) {
|
|
22
23
|
return plugins.push(StatePluginHandleMap[plugin](config[plugin]));
|
|
23
24
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
var storeConfig = {};
|
|
26
|
+
for (var _i = 0, _Object$entries = Object.entries(config); _i < _Object$entries.length; _i++) {
|
|
27
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
28
|
+
key = _Object$entries$_i[0],
|
|
29
|
+
value = _Object$entries$_i[1];
|
|
30
|
+
if (internalPlugins.includes(key)) {
|
|
31
|
+
plugins.push(StatePluginHandleMap[key](value));
|
|
32
|
+
} else {
|
|
33
|
+
storeConfig[key] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
storeConfig.plugins = plugins;
|
|
37
|
+
return storeConfig;
|
|
27
38
|
};
|
|
28
39
|
var state = function state(config) {
|
|
29
40
|
return {
|
|
@@ -2,5 +2,6 @@ import { routerPlugin } from './plugin';
|
|
|
2
2
|
import type { SingleRouteConfig, RouterConfig } from './types';
|
|
3
3
|
export type { SingleRouteConfig, RouterConfig };
|
|
4
4
|
export default routerPlugin;
|
|
5
|
+
export { modifyRoutes } from './plugin';
|
|
5
6
|
export * from 'react-router-dom';
|
|
6
7
|
export * from './withRouter';
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import type { Plugin } from '../../core';
|
|
2
|
-
import type { RouterConfig } from './types';
|
|
2
|
+
import type { RouterConfig, Routes } from './types';
|
|
3
|
+
export declare let finalRouteConfig: RouterConfig['routesConfig'];
|
|
4
|
+
export declare let beforeRenderRouter: boolean;
|
|
5
|
+
export declare function modifyRoutes(modifyFunction: (routes: Routes) => Routes): void;
|
|
3
6
|
export declare const routerPlugin: ({
|
|
4
7
|
serverBase,
|
|
5
8
|
supportHtml5History,
|
|
9
|
+
basename,
|
|
6
10
|
routesConfig,
|
|
7
11
|
createRoutes
|
|
8
12
|
}: RouterConfig) => Plugin;
|
|
@@ -3,6 +3,7 @@ import { SSRServerContext } from '../../ssr/serverRender/types';
|
|
|
3
3
|
import type { RouterConfig } from './types';
|
|
4
4
|
export declare function createFetchHeaders(requestHeaders: SSRServerContext['request']['headers']): Headers;
|
|
5
5
|
export declare const routerPlugin: ({
|
|
6
|
+
basename,
|
|
6
7
|
routesConfig,
|
|
7
8
|
createRoutes
|
|
8
9
|
}: RouterConfig) => Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'react-router-dom/server';
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { type Model } from '@modern-js-reduck/store';
|
|
1
2
|
import type { Plugin } from '../../core';
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
declare type StatePluginType = 'immer' | 'effects' | 'autoActions' | 'devtools';
|
|
4
|
+
declare type StateExtraType = {
|
|
5
|
+
initialState: any;
|
|
6
|
+
models: Array<Model>;
|
|
7
|
+
};
|
|
8
|
+
export declare type StateConfig = Partial<Record<StatePluginType, boolean> & StateExtraType>;
|
|
4
9
|
declare const state: (config: StateConfig) => Plugin;
|
|
5
10
|
export default state;
|
|
6
11
|
export * from '../plugins';
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.0-
|
|
14
|
+
"version": "2.0.0-canary.0",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=14.17.6"
|
|
17
17
|
},
|
|
@@ -53,6 +53,11 @@
|
|
|
53
53
|
"node": "./dist/js/node/document/index.js",
|
|
54
54
|
"default": "./dist/js/treeshaking/document/index.js"
|
|
55
55
|
},
|
|
56
|
+
"./document/cli": {
|
|
57
|
+
"jsnext:source": "./src/document/cli/index.ts",
|
|
58
|
+
"node": "./dist/js/node/document/cli/index.js",
|
|
59
|
+
"default": "./dist/js/treeshaking/document/cli/index.js"
|
|
60
|
+
},
|
|
56
61
|
"./ssr": {
|
|
57
62
|
"jsnext:source": "./src/ssr/index.ts",
|
|
58
63
|
"node": "./dist/js/node/ssr/index",
|
|
@@ -72,10 +77,10 @@
|
|
|
72
77
|
"node": "./dist/js/node/router/index.js",
|
|
73
78
|
"default": "./dist/js/treeshaking/router/index.js"
|
|
74
79
|
},
|
|
75
|
-
"./router
|
|
76
|
-
"jsnext:source": "./src/router/server
|
|
77
|
-
"node": "./dist/js/node/router/server
|
|
78
|
-
"default": "./dist/js/treeshaking/router/server
|
|
80
|
+
"./router/server": {
|
|
81
|
+
"jsnext:source": "./src/router/server.ts",
|
|
82
|
+
"node": "./dist/js/node/router/server.js",
|
|
83
|
+
"default": "./dist/js/treeshaking/router/server.js"
|
|
79
84
|
}
|
|
80
85
|
},
|
|
81
86
|
"typesVersions": {
|
|
@@ -101,6 +106,9 @@
|
|
|
101
106
|
"document": [
|
|
102
107
|
"./dist/types/document/index.d.ts"
|
|
103
108
|
],
|
|
109
|
+
"document/cli": [
|
|
110
|
+
"./dist/types/document/cli/index.d.ts"
|
|
111
|
+
],
|
|
104
112
|
"ssr": [
|
|
105
113
|
"./dist/types/ssr/index.d.ts"
|
|
106
114
|
],
|
|
@@ -110,8 +118,8 @@
|
|
|
110
118
|
"router": [
|
|
111
119
|
"./dist/types/router/index.d.ts"
|
|
112
120
|
],
|
|
113
|
-
"router
|
|
114
|
-
"./dist/types/router/server
|
|
121
|
+
"router/server": [
|
|
122
|
+
"./dist/types/router/runtime/server.d.ts"
|
|
115
123
|
]
|
|
116
124
|
}
|
|
117
125
|
},
|
|
@@ -122,12 +130,12 @@
|
|
|
122
130
|
"@loadable/webpack-plugin": "5.15.2",
|
|
123
131
|
"@loadable/component": "^5.15.0",
|
|
124
132
|
"@loadable/server": "^5.15.1",
|
|
125
|
-
"@modern-js-reduck/plugin-auto-actions": "^1.
|
|
126
|
-
"@modern-js-reduck/plugin-devtools": "^1.
|
|
127
|
-
"@modern-js-reduck/plugin-effects": "^1.
|
|
128
|
-
"@modern-js-reduck/plugin-immutable": "^1.
|
|
129
|
-
"@modern-js-reduck/react": "^1.
|
|
130
|
-
"@modern-js-reduck/store": "^1.
|
|
133
|
+
"@modern-js-reduck/plugin-auto-actions": "^1.1.4",
|
|
134
|
+
"@modern-js-reduck/plugin-devtools": "^1.1.4",
|
|
135
|
+
"@modern-js-reduck/plugin-effects": "^1.1.4",
|
|
136
|
+
"@modern-js-reduck/plugin-immutable": "^1.1.4",
|
|
137
|
+
"@modern-js-reduck/react": "^1.1.4",
|
|
138
|
+
"@modern-js-reduck/store": "^1.1.4",
|
|
131
139
|
"@types/loadable__component": "^5.13.4",
|
|
132
140
|
"@types/react-helmet": "^6.1.2",
|
|
133
141
|
"@types/redux-logger": "^3.0.9",
|
|
@@ -136,16 +144,16 @@
|
|
|
136
144
|
"invariant": "^2.2.4",
|
|
137
145
|
"react-helmet": "^6.1.0",
|
|
138
146
|
"@remix-run/node": "^1.7.0",
|
|
139
|
-
"@remix-run/router": "^1.0.
|
|
147
|
+
"@remix-run/router": "^1.0.4",
|
|
140
148
|
"react-is": "^18",
|
|
141
|
-
"react-router-dom": "^6.4.
|
|
149
|
+
"react-router-dom": "^6.4.4",
|
|
142
150
|
"react-side-effect": "^2.1.1",
|
|
143
151
|
"redux-logger": "^3.0.6",
|
|
144
152
|
"serialize-javascript": "^6.0.0",
|
|
145
153
|
"styled-components": "^5.3.1",
|
|
146
|
-
"@modern-js/
|
|
147
|
-
"@modern-js/
|
|
148
|
-
"@modern-js/
|
|
154
|
+
"@modern-js/types": "2.0.0-beta.3",
|
|
155
|
+
"@modern-js/utils": "2.0.0-beta.3",
|
|
156
|
+
"@modern-js/plugin": "2.0.0-beta.3"
|
|
149
157
|
},
|
|
150
158
|
"peerDependencies": {
|
|
151
159
|
"react": ">=17",
|
|
@@ -166,12 +174,12 @@
|
|
|
166
174
|
"react-dom": "^18",
|
|
167
175
|
"ts-jest": "^27.0.4",
|
|
168
176
|
"typescript": "^4",
|
|
169
|
-
"@modern-js/
|
|
170
|
-
"@modern-js/server-core": "2.0.0-beta.
|
|
171
|
-
"@
|
|
172
|
-
"@
|
|
173
|
-
"@modern-js/
|
|
174
|
-
"@scripts/jest-config": "2.0.0-beta.
|
|
177
|
+
"@modern-js/utils": "2.0.0-beta.3",
|
|
178
|
+
"@modern-js/server-core": "2.0.0-beta.3",
|
|
179
|
+
"@scripts/build": "2.0.0-beta.3",
|
|
180
|
+
"@modern-js/app-tools": "2.0.0-beta.3",
|
|
181
|
+
"@modern-js/core": "2.0.0-beta.3",
|
|
182
|
+
"@scripts/jest-config": "2.0.0-beta.3"
|
|
175
183
|
},
|
|
176
184
|
"sideEffects": false,
|
|
177
185
|
"modernConfig": {},
|