@shuvi/platform-web 1.0.0-rc.3 → 1.0.0-rc.4
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/esm/shared/appTypes.d.ts +2 -2
- package/esm/shuvi-app/app/client.d.ts +2 -0
- package/esm/shuvi-app/app/client.js +2 -1
- package/esm/shuvi-app/dev/eventsource.d.ts +1 -0
- package/esm/shuvi-app/dev/eventsource.js +60 -0
- package/esm/shuvi-app/dev/hotDevClient.d.ts +33 -0
- package/esm/shuvi-app/dev/hotDevClient.js +348 -0
- package/esm/shuvi-app/dev/index.d.ts +3 -0
- package/esm/shuvi-app/dev/index.js +27 -0
- package/esm/shuvi-app/dev/websocket.d.ts +17 -0
- package/esm/shuvi-app/dev/websocket.js +61 -0
- package/esm/shuvi-app/entry/client/app.d.ts +2 -1
- package/esm/shuvi-app/entry/client/app.js +2 -2
- package/esm/shuvi-app/entry/client/run.dev.js +4 -4
- package/esm/shuvi-app/entry/server/index.d.ts +5 -4
- package/esm/shuvi-app/entry/server/index.js +5 -4
- package/esm/shuvi-app/react/getRoutes.d.ts +2 -2
- package/esm/shuvi-app/react/getRoutes.js +6 -7
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +7 -1
- package/esm/shuvi-app/react/redox-react/runtime.js +3 -1
- package/esm/shuvi-app/shuvi-runtime-index.js +1 -1
- package/lib/node/features/filesystem-routes/index.d.ts +1 -1
- package/lib/node/features/filesystem-routes/index.js +17 -7
- package/lib/node/features/filesystem-routes/page/routes.d.ts +2 -2
- package/lib/node/features/filesystem-routes/page/routes.js +29 -11
- package/lib/node/features/html-render/index.d.ts +3 -18
- package/lib/node/features/html-render/index.js +87 -16
- package/lib/node/features/{main → html-render/lib}/buildHtml.d.ts +0 -0
- package/lib/node/features/{main → html-render/lib}/buildHtml.js +0 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +2 -2
- package/lib/node/features/html-render/lib/generateFilesByRoutId.js +3 -3
- package/lib/node/features/{main → html-render/lib}/generateResource.d.ts +0 -0
- package/lib/node/features/{main → html-render/lib}/generateResource.js +0 -0
- package/lib/node/features/index.d.ts +3 -31
- package/lib/node/features/index.js +9 -8
- package/lib/node/features/model/index.d.ts +1 -1
- package/lib/node/features/model/runtime.d.ts +0 -5
- package/lib/node/features/model/runtime.js +11 -17
- package/lib/node/features/model/server.js +2 -3
- package/lib/node/features/model/shuvi-app.d.ts +1 -1
- package/lib/node/features/on-demand-compile-page/index.d.ts +15 -13
- package/lib/node/features/on-demand-compile-page/index.js +4 -1
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +2 -4
- package/lib/node/features/webpack-watch-wait-for-file-builder/index.d.ts +16 -0
- package/lib/node/features/webpack-watch-wait-for-file-builder/index.js +25 -0
- package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.d.ts +12 -0
- package/lib/node/features/webpack-watch-wait-for-file-builder/webpack-watch-wait-for-file-builder-plugin.js +32 -0
- package/lib/node/index.js +1 -3
- package/lib/node/shuvi-type-extensions-node.d.ts +2 -0
- package/lib/node/targets/react/bundler/index.d.ts +1 -1
- package/lib/node/targets/react/bundler/index.js +5 -0
- package/lib/node/targets/react/index.d.ts +2 -2
- package/lib/node/targets/react/redox-react/index.d.ts +1 -1
- package/lib/shared/appTypes.d.ts +2 -2
- package/package.json +17 -12
- package/shuvi-env.d.ts +10 -0
- package/shuvi-image.d.ts +54 -0
- package/shuvi-type-extensions-node.js +1 -0
- package/shuvi-type-extensions-runtime.d.ts +2 -2
- package/esm/shuvi-app/dev/webpackHotDevClient.d.ts +0 -5
- package/esm/shuvi-app/dev/webpackHotDevClient.js +0 -34
- package/lib/node/features/main/index.d.ts +0 -3
- package/lib/node/features/main/index.js +0 -82
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IPageRouteRecord
|
|
2
|
-
export default function getRoutes(routes:
|
|
1
|
+
import { IPageRouteRecord } from '@shuvi/platform-shared/shared';
|
|
2
|
+
export default function getRoutes(routes: IPageRouteRecord[]): IPageRouteRecord[];
|
|
@@ -13,18 +13,17 @@ import { loadRouteComponent } from './loadRouteComponent';
|
|
|
13
13
|
export default function getRoutes(routes) {
|
|
14
14
|
const getRoutesWithRequire = (routes) => routes.map(x => {
|
|
15
15
|
const originalRoute = Object.assign({}, x);
|
|
16
|
-
const {
|
|
16
|
+
const { __componentRawRequest__, __import__, __resolveWeak__, children } = originalRoute, rest = __rest(originalRoute, ["__componentRawRequest__", "__import__", "__resolveWeak__", "children"]);
|
|
17
17
|
const route = Object.assign({}, rest);
|
|
18
18
|
if (children) {
|
|
19
19
|
route.children = getRoutesWithRequire(children);
|
|
20
20
|
}
|
|
21
|
-
if (
|
|
22
|
-
route.component = loadRouteComponent(__import__, {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
21
|
+
if (__import__) {
|
|
22
|
+
route.component = loadRouteComponent(__import__, Object.assign({ webpack: __resolveWeak__ }, (__componentRawRequest__ && {
|
|
23
|
+
modules: [__componentRawRequest__]
|
|
24
|
+
})));
|
|
26
25
|
}
|
|
27
|
-
return Object.assign({
|
|
26
|
+
return Object.assign({ __componentRawRequest__, __resolveWeak__ }, route);
|
|
28
27
|
});
|
|
29
28
|
const routesWithRequire = getRoutesWithRequire(routes || []);
|
|
30
29
|
return routesWithRequire;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { IStoreManager } from '@shuvi/redox';
|
|
2
|
+
declare module '@shuvi/runtime' {
|
|
3
|
+
interface CustomAppContext {
|
|
4
|
+
store: IStoreManager;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").BuiltInRuntimePluginHooks & import("@shuvi/runtime").CustomRuntimePluginHooks, void>;
|
|
2
8
|
export default _default;
|
|
@@ -11,6 +11,8 @@ import { createRuntimePlugin } from '@shuvi/platform-shared/shared';
|
|
|
11
11
|
import { RedoxWrapper } from './RedoxWrapper';
|
|
12
12
|
export default createRuntimePlugin({
|
|
13
13
|
appComponent: (App, appContext) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
return RedoxWrapper(App,
|
|
14
|
+
return RedoxWrapper(App, {
|
|
15
|
+
storeManager: appContext.store
|
|
16
|
+
});
|
|
15
17
|
})
|
|
16
18
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
// exported by @shuvi/
|
|
1
|
+
// exported by @shuvi/runtime
|
|
2
2
|
export {};
|
|
@@ -13,7 +13,7 @@ declare const _default: {
|
|
|
13
13
|
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
14
14
|
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
15
15
|
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
16
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").
|
|
16
|
+
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
|
|
17
17
|
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
18
18
|
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
19
19
|
};
|
|
@@ -50,9 +50,18 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
50
50
|
setup: ({ addHooks }) => {
|
|
51
51
|
addHooks({ addRoutes: hooks_1.addRoutes, addMiddlewareRoutes: hooks_1.addMiddlewareRoutes });
|
|
52
52
|
},
|
|
53
|
-
addRuntimeFile: ({ defineFile }, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
addRuntimeFile: ({ defineFile, getContent }, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
54
|
const { config: { routes: pageRoutes, middlewareRoutes, apiRoutes, conventionRoutes }, paths, pluginRunner, phase } = context;
|
|
55
55
|
const isBuildPhase = phase === 'PHASE_PRODUCTION_BUILD';
|
|
56
|
+
const rawRoutes = defineFile({
|
|
57
|
+
name: 'virtual-raw-routes.js',
|
|
58
|
+
virtual: true,
|
|
59
|
+
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const rawRoutes = yield (0, node_1.getRawRoutesFromDir)(paths.routesDir, conventionRoutes.exclude);
|
|
61
|
+
return rawRoutes;
|
|
62
|
+
}),
|
|
63
|
+
dependencies: [paths.routesDir]
|
|
64
|
+
});
|
|
56
65
|
const pageRoutesFile = defineFile({
|
|
57
66
|
name: 'routes.js',
|
|
58
67
|
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -62,7 +71,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
62
71
|
routes = pageRoutes;
|
|
63
72
|
}
|
|
64
73
|
else {
|
|
65
|
-
const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(
|
|
74
|
+
const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
|
|
66
75
|
if (isBuildPhase) {
|
|
67
76
|
warnings.forEach(warning => {
|
|
68
77
|
console.warn(warning.msg);
|
|
@@ -77,7 +86,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
77
86
|
(0, page_1.setRoutes)(normalizedRoutes);
|
|
78
87
|
return (0, page_1.generateRoutesContent)(normalizedRoutes);
|
|
79
88
|
}),
|
|
80
|
-
dependencies: [
|
|
89
|
+
dependencies: [rawRoutes]
|
|
81
90
|
});
|
|
82
91
|
const apiRoutesFile = defineFile({
|
|
83
92
|
name: 'apiRoutes.js',
|
|
@@ -88,7 +97,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
88
97
|
routes = apiRoutes;
|
|
89
98
|
}
|
|
90
99
|
else {
|
|
91
|
-
const { routes: _routes, warnings } = yield (0, node_1.getApiRoutes)(
|
|
100
|
+
const { routes: _routes, warnings } = yield (0, node_1.getApiRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
|
|
92
101
|
if (isBuildPhase) {
|
|
93
102
|
warnings.forEach(warning => {
|
|
94
103
|
console.warn(warning);
|
|
@@ -98,7 +107,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
98
107
|
}
|
|
99
108
|
return (0, api_1.generateRoutesContent)(routes, paths.routesDir);
|
|
100
109
|
}),
|
|
101
|
-
dependencies: [
|
|
110
|
+
dependencies: [rawRoutes]
|
|
102
111
|
});
|
|
103
112
|
const middlewareRoutesFile = defineFile({
|
|
104
113
|
name: 'middlewareRoutes.js',
|
|
@@ -109,7 +118,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
109
118
|
routes = middlewareRoutes;
|
|
110
119
|
}
|
|
111
120
|
else {
|
|
112
|
-
const { routes: _routes, warnings } = yield (0, node_1.getMiddlewareRoutes)(
|
|
121
|
+
const { routes: _routes, warnings } = yield (0, node_1.getMiddlewareRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
|
|
113
122
|
if (isBuildPhase) {
|
|
114
123
|
warnings.forEach(warning => {
|
|
115
124
|
console.warn(warning);
|
|
@@ -122,7 +131,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
122
131
|
baseDir: paths.routesDir
|
|
123
132
|
});
|
|
124
133
|
}),
|
|
125
|
-
dependencies: [
|
|
134
|
+
dependencies: [rawRoutes]
|
|
126
135
|
});
|
|
127
136
|
const loadersFile = defineFile({
|
|
128
137
|
name: 'loaders.js',
|
|
@@ -167,6 +176,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
167
176
|
dependencies: [loadersFile]
|
|
168
177
|
});
|
|
169
178
|
return [
|
|
179
|
+
rawRoutes,
|
|
170
180
|
pageRoutesFile,
|
|
171
181
|
apiRoutesFile,
|
|
172
182
|
middlewareRoutesFile,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { IPageRouteConfig, IPageRouteConfigWithId } from '@shuvi/platform-shared/shared';
|
|
2
2
|
export { IPageRouteConfig };
|
|
3
3
|
/**
|
|
4
|
-
* returns JSON string of
|
|
4
|
+
* returns JSON string of IPageRouteConfigWithId
|
|
5
5
|
*/
|
|
6
|
-
export declare function serializeRoutes(routes: IPageRouteConfigWithId[]): string;
|
|
6
|
+
export declare function serializeRoutes(routes: IPageRouteConfigWithId[], isServer: boolean): string;
|
|
7
7
|
export declare function normalizeRoutes(routes: IPageRouteConfig[], componentDir: string, parentPath?: string): IPageRouteConfigWithId[];
|
|
8
8
|
export declare const generateRoutesContent: (routes: IPageRouteConfigWithId[]) => string;
|
|
@@ -10,18 +10,23 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
}
|
|
11
11
|
return t;
|
|
12
12
|
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
13
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
17
|
exports.generateRoutesContent = exports.normalizeRoutes = exports.serializeRoutes = void 0;
|
|
15
18
|
const crypto_1 = require("crypto");
|
|
19
|
+
const querystring_1 = __importDefault(require("querystring"));
|
|
16
20
|
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
17
21
|
const file_1 = require("@shuvi/utils/lib/file");
|
|
18
22
|
function genRouteId(filepath) {
|
|
19
23
|
return (0, crypto_1.createHash)('md4').update(filepath).digest('hex').substr(0, 4);
|
|
20
24
|
}
|
|
25
|
+
const KEEP_SYMBOL = querystring_1.default.stringify({ keep: ['default'] });
|
|
21
26
|
/**
|
|
22
|
-
* returns JSON string of
|
|
27
|
+
* returns JSON string of IPageRouteConfigWithId
|
|
23
28
|
*/
|
|
24
|
-
function serializeRoutes(routes) {
|
|
29
|
+
function serializeRoutes(routes, isServer) {
|
|
25
30
|
let res = '';
|
|
26
31
|
for (let index = 0; index < routes.length; index++) {
|
|
27
32
|
const _a = routes[index], { children: childRoutes } = _a, route = __rest(_a, ["children"]);
|
|
@@ -33,16 +38,18 @@ function serializeRoutes(routes) {
|
|
|
33
38
|
if (key === 'component') {
|
|
34
39
|
const { component } = route;
|
|
35
40
|
const componentSource = component;
|
|
36
|
-
const
|
|
41
|
+
const componentRequest = `${componentSource}?${constants_1.ROUTE_RESOURCE_QUERYSTRING}&${KEEP_SYMBOL}`;
|
|
37
42
|
// `webpackExports` works with production and optimization.minimize, check compiled dist
|
|
38
|
-
|
|
39
|
-
`
|
|
40
|
-
__componentSource__: "${componentSource}"
|
|
43
|
+
if (isServer) {
|
|
44
|
+
strRoute += `__componentRawRequest__: "${componentRequest}",\n`;
|
|
45
|
+
strRoute += `__componentSource__: "${componentSource}",\n`;
|
|
46
|
+
}
|
|
47
|
+
strRoute += `
|
|
41
48
|
__import__: () => import(
|
|
42
49
|
/* webpackChunkName: "page-${id}" */
|
|
43
50
|
/* webpackExports: "default" */
|
|
44
|
-
"${
|
|
45
|
-
__resolveWeak__: () => [require.resolveWeak("${
|
|
51
|
+
"${componentRequest}"),
|
|
52
|
+
__resolveWeak__: () => [require.resolveWeak("${componentRequest}")]`.trim();
|
|
46
53
|
}
|
|
47
54
|
else {
|
|
48
55
|
strRoute += `${key}: ${JSON.stringify(route[key])}`;
|
|
@@ -50,7 +57,7 @@ __resolveWeak__: () => [require.resolveWeak("${componentSourceWithAffix}")]`.tri
|
|
|
50
57
|
strRoute += `,\n`;
|
|
51
58
|
}
|
|
52
59
|
if (childRoutes && childRoutes.length > 0) {
|
|
53
|
-
strRoute += `children: ${serializeRoutes(childRoutes)},\n`;
|
|
60
|
+
strRoute += `children: ${serializeRoutes(childRoutes, isServer)},\n`;
|
|
54
61
|
}
|
|
55
62
|
res += `{${strRoute}},\n`;
|
|
56
63
|
}
|
|
@@ -77,7 +84,18 @@ function normalizeRoutes(routes, componentDir, parentPath = '') {
|
|
|
77
84
|
}
|
|
78
85
|
exports.normalizeRoutes = normalizeRoutes;
|
|
79
86
|
const generateRoutesContent = (routes) => {
|
|
80
|
-
const
|
|
81
|
-
|
|
87
|
+
const serverRoutes = serializeRoutes(routes, true);
|
|
88
|
+
const clientRoutes = serializeRoutes(routes, false);
|
|
89
|
+
return `
|
|
90
|
+
let routes;
|
|
91
|
+
|
|
92
|
+
if (typeof windows === 'undefined') {
|
|
93
|
+
routes = ${serverRoutes}
|
|
94
|
+
} else {
|
|
95
|
+
routes = ${clientRoutes}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default routes
|
|
99
|
+
`;
|
|
82
100
|
};
|
|
83
101
|
exports.generateRoutesContent = generateRoutesContent;
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
+
import { IPlatformContext, ResolvedPlugin } from '@shuvi/service/lib/core';
|
|
1
2
|
export { getPageMiddleware, IHtmlDocument, ITemplateData, IViewServer, IViewClient } from './lib';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
5
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
8
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
9
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
10
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
11
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
12
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
13
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
14
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
15
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
16
|
-
server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/service/lib/server/pluginTypes").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
|
|
17
|
-
types: string;
|
|
18
|
-
};
|
|
19
|
-
export default _default;
|
|
3
|
+
/** This plugin uses `platformContext` so that it is set to a plugin getter */
|
|
4
|
+
export declare const getPlugin: (platformContext: IPlatformContext) => ResolvedPlugin;
|
|
@@ -1,28 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPageMiddleware = void 0;
|
|
15
|
+
exports.getPlugin = exports.getPageMiddleware = void 0;
|
|
7
16
|
const service_1 = require("@shuvi/service");
|
|
17
|
+
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
18
|
+
const config_1 = require("@shuvi/toolpack/lib/webpack/config");
|
|
8
19
|
const paths_1 = require("../../paths");
|
|
20
|
+
const middlewares_1 = require("../middlewares");
|
|
21
|
+
const generateResource_1 = __importDefault(require("./lib/generateResource"));
|
|
22
|
+
const buildHtml_1 = require("./lib/buildHtml");
|
|
9
23
|
const server_1 = __importDefault(require("./server"));
|
|
24
|
+
function getServerEntry() {
|
|
25
|
+
return {
|
|
26
|
+
[service_1.BUILD_SERVER_FILE_SERVER]: [(0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/server')]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
10
29
|
var lib_1 = require("./lib");
|
|
11
30
|
Object.defineProperty(exports, "getPageMiddleware", { enumerable: true, get: function () { return lib_1.getPageMiddleware; } });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
name
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
/** This plugin uses `platformContext` so that it is set to a plugin getter */
|
|
32
|
+
const getPlugin = (platformContext) => {
|
|
33
|
+
const core = (0, service_1.createPlugin)({
|
|
34
|
+
configWebpack: (chain, { name }) => {
|
|
35
|
+
if (name === constants_1.BUNDLER_DEFAULT_TARGET) {
|
|
36
|
+
chain.merge({
|
|
37
|
+
entry: {
|
|
38
|
+
[service_1.BUILD_CLIENT_RUNTIME_POLYFILL]: ['@shuvi/app/core/polyfill'],
|
|
39
|
+
[service_1.BUILD_CLIENT_RUNTIME_MAIN]: [
|
|
40
|
+
(0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/client')
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return chain;
|
|
46
|
+
},
|
|
47
|
+
addExtraTarget: ({ createConfig }, context) => {
|
|
48
|
+
const serverWebpackHelpers = (0, config_1.webpackHelpers)();
|
|
49
|
+
const serverChain = createConfig({
|
|
50
|
+
name: constants_1.BUNDLER_TARGET_SERVER,
|
|
51
|
+
node: true,
|
|
52
|
+
entry: getServerEntry(),
|
|
53
|
+
outputDir: service_1.BUILD_SERVER_DIR,
|
|
54
|
+
webpackHelpers: serverWebpackHelpers
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
name: constants_1.BUNDLER_TARGET_SERVER,
|
|
58
|
+
chain: serverChain
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
addRuntimeFile: ({ defineFile }, context) => {
|
|
62
|
+
const { config: { router: { history } } } = context;
|
|
63
|
+
const routerConfigFile = defineFile({
|
|
64
|
+
name: 'routerConfig.js',
|
|
65
|
+
content: () => {
|
|
66
|
+
return `export const historyMode = "${history}";`;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return [routerConfigFile];
|
|
70
|
+
},
|
|
71
|
+
addRuntimeService: () => [
|
|
72
|
+
{
|
|
73
|
+
source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/shuvi-runtime-index'),
|
|
74
|
+
exported: '*'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/shuvi-runtime-server'),
|
|
78
|
+
filepath: 'server.ts',
|
|
79
|
+
exported: '*'
|
|
19
80
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
81
|
+
],
|
|
82
|
+
addResource: context => (0, generateResource_1.default)(context),
|
|
83
|
+
afterBuild: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
yield (0, buildHtml_1.buildHtml)({
|
|
85
|
+
context,
|
|
86
|
+
serverPlugins: platformContext.serverPlugins,
|
|
87
|
+
getMiddlewares: middlewares_1.getMiddlewares,
|
|
88
|
+
pathname: '/',
|
|
89
|
+
filename: 'index.html'
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
core,
|
|
95
|
+
server: server_1.default,
|
|
96
|
+
types: (0, paths_1.resolvePkgFile)('lib/node/features/html-render/shuvi-app.d.ts')
|
|
97
|
+
};
|
|
28
98
|
};
|
|
99
|
+
exports.getPlugin = getPlugin;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IManifest } from '@shuvi/toolpack/lib/webpack/types';
|
|
2
|
-
import {
|
|
3
|
-
export default function generateFilesByRoutId(assetMap: IManifest, routes:
|
|
2
|
+
import { IPageRouteRecord } from '@shuvi/platform-shared/shared';
|
|
3
|
+
export default function generateFilesByRoutId(assetMap: IManifest, routes: IPageRouteRecord[]): Record<string, string[]>;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
function generateFilesByRoutId(assetMap, routes) {
|
|
4
4
|
let filesByRoutId = {};
|
|
5
5
|
const loadable = assetMap.loadble;
|
|
6
|
-
routes.forEach(({ id,
|
|
7
|
-
if (
|
|
8
|
-
filesByRoutId[id] = loadable[
|
|
6
|
+
routes.forEach(({ id, __componentRawRequest__ }) => {
|
|
7
|
+
if (__componentRawRequest__) {
|
|
8
|
+
filesByRoutId[id] = loadable[__componentRawRequest__].files;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
return filesByRoutId;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { IPlatformContext, ResolvedPlugin } from '@shuvi/service/lib/core';
|
|
2
|
+
export { buildHtml } from './html-render/lib/buildHtml';
|
|
2
3
|
export { getMiddlewares, getMiddlewaresBeforeDevMiddlewares } from './middlewares';
|
|
3
|
-
export
|
|
4
|
-
export declare const featurePlugins: (import("@shuvi/hook").IPluginInstance<{
|
|
5
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
6
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
8
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
9
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
10
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
11
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
12
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
13
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
14
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
15
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
16
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext> | {
|
|
17
|
-
core: import("@shuvi/hook").IPluginInstance<{
|
|
18
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
19
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
20
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
21
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
22
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
23
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
24
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
25
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
26
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
27
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
28
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
29
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
30
|
-
} | {
|
|
31
|
-
server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/service/lib/server/pluginTypes").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
|
|
32
|
-
})[];
|
|
4
|
+
export declare const getPlugins: (platformContext: IPlatformContext) => ResolvedPlugin[];
|
|
@@ -3,23 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getPlugins = exports.getMiddlewaresBeforeDevMiddlewares = exports.getMiddlewares = exports.buildHtml = void 0;
|
|
7
7
|
const on_demand_compile_page_1 = __importDefault(require("./on-demand-compile-page"));
|
|
8
|
-
const html_render_1 =
|
|
8
|
+
const html_render_1 = require("./html-render");
|
|
9
9
|
const custom_server_1 = __importDefault(require("./custom-server"));
|
|
10
10
|
const model_1 = __importDefault(require("./model"));
|
|
11
11
|
const filesystem_routes_1 = __importDefault(require("./filesystem-routes"));
|
|
12
|
-
|
|
12
|
+
const webpack_watch_wait_for_file_builder_1 = __importDefault(require("./webpack-watch-wait-for-file-builder"));
|
|
13
|
+
var buildHtml_1 = require("./html-render/lib/buildHtml");
|
|
13
14
|
Object.defineProperty(exports, "buildHtml", { enumerable: true, get: function () { return buildHtml_1.buildHtml; } });
|
|
14
15
|
var middlewares_1 = require("./middlewares");
|
|
15
16
|
Object.defineProperty(exports, "getMiddlewares", { enumerable: true, get: function () { return middlewares_1.getMiddlewares; } });
|
|
16
17
|
Object.defineProperty(exports, "getMiddlewaresBeforeDevMiddlewares", { enumerable: true, get: function () { return middlewares_1.getMiddlewaresBeforeDevMiddlewares; } });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exports.featurePlugins = [
|
|
18
|
+
const getPlugins = (platformContext) => [
|
|
19
|
+
(0, html_render_1.getPlugin)(platformContext),
|
|
20
20
|
on_demand_compile_page_1.default,
|
|
21
21
|
filesystem_routes_1.default,
|
|
22
|
-
html_render_1.default,
|
|
23
22
|
custom_server_1.default,
|
|
24
|
-
model_1.default
|
|
23
|
+
model_1.default,
|
|
24
|
+
webpack_watch_wait_for_file_builder_1.default
|
|
25
25
|
];
|
|
26
|
+
exports.getPlugins = getPlugins;
|
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
10
10
|
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
11
11
|
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
12
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").
|
|
12
|
+
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
|
|
13
13
|
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
14
14
|
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
15
15
|
runtime: {
|
|
@@ -4,10 +4,5 @@ export declare type InitRedox = (params: {
|
|
|
4
4
|
initialState: any;
|
|
5
5
|
ctx: IAppContext;
|
|
6
6
|
}) => IStoreManager;
|
|
7
|
-
declare module '@shuvi/runtime' {
|
|
8
|
-
interface CustomAppContext {
|
|
9
|
-
storeManager?: IStoreManager;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
7
|
declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").BuiltInRuntimePluginHooks & import("@shuvi/runtime").CustomRuntimePluginHooks, void>;
|
|
13
8
|
export default _default;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const redox_1 = require("@shuvi/redox");
|
|
4
4
|
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
5
|
-
let
|
|
5
|
+
let currentStore;
|
|
6
6
|
const isServer = typeof window === 'undefined';
|
|
7
7
|
// for client, singleton mode
|
|
8
8
|
// for server, return new store
|
|
@@ -21,27 +21,21 @@ const initStore = ({ initialState, ctx }) => {
|
|
|
21
21
|
return createStoreInstance();
|
|
22
22
|
}
|
|
23
23
|
// for client is singleton, just init once
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
if (!currentStore) {
|
|
25
|
+
currentStore = createStoreInstance();
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
return currentStoreManager;
|
|
27
|
+
return currentStore;
|
|
29
28
|
};
|
|
30
29
|
exports.default = (0, shared_1.createRuntimePlugin)({
|
|
31
30
|
appContext: ctx => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
initialState = (0, shared_1.getPageData)('redox');
|
|
36
|
-
}
|
|
37
|
-
if (ctx.pageData && ctx.pageData.redox) {
|
|
38
|
-
initialState = ctx.pageData.redox;
|
|
39
|
-
}
|
|
40
|
-
ctx.storeManager = initStore({
|
|
41
|
-
ctx,
|
|
42
|
-
initialState
|
|
43
|
-
});
|
|
31
|
+
let initialState = {};
|
|
32
|
+
if (!isServer) {
|
|
33
|
+
initialState = (0, shared_1.getPageData)('shuviInitialState', {});
|
|
44
34
|
}
|
|
35
|
+
ctx.store = initStore({
|
|
36
|
+
ctx,
|
|
37
|
+
initialState
|
|
38
|
+
});
|
|
45
39
|
return ctx;
|
|
46
40
|
}
|
|
47
41
|
});
|
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const service_1 = require("@shuvi/service");
|
|
4
4
|
exports.default = (0, service_1.createServerPlugin)({
|
|
5
5
|
getPageData: appContext => {
|
|
6
|
-
const {
|
|
7
|
-
delete appContext.storeManager;
|
|
6
|
+
const { store } = appContext;
|
|
8
7
|
return {
|
|
9
|
-
|
|
8
|
+
shuviInitialState: store.getState()
|
|
10
9
|
};
|
|
11
10
|
}
|
|
12
11
|
});
|