@shuvi/platform-web 1.0.0-rc.2 → 1.0.0-rc.20
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 +12 -6
- package/esm/shared/configTypes.d.ts +1 -3
- package/esm/shared/constants.d.ts +8 -0
- package/esm/shared/constants.js +8 -0
- package/esm/shared/htmlRenderer.d.ts +33 -0
- package/esm/shared/{serverTypes.js → htmlRenderer.js} +0 -0
- package/esm/shared/index.d.ts +2 -1
- package/esm/shared/index.js +2 -1
- package/esm/shared/renderTypes.d.ts +8 -7
- package/esm/shared/routeTypes.d.ts +4 -9
- package/esm/shuvi-app/app/client.d.ts +2 -1
- package/esm/shuvi-app/app/client.js +13 -17
- package/esm/shuvi-app/app/server.js +13 -9
- 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 +32 -0
- package/esm/shuvi-app/dev/hotDevClient.js +327 -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 +16 -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 +13 -6
- package/esm/shuvi-app/entry/client/index.js +1 -1
- package/esm/shuvi-app/entry/client/run.dev.js +15 -16
- 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/helper/serializeServerError.d.ts +2 -0
- package/esm/shuvi-app/helper/serializeServerError.js +21 -0
- package/esm/shuvi-app/react/AppContainer.d.ts +4 -5
- package/esm/shuvi-app/react/AppContainer.jsx +4 -5
- package/esm/shuvi-app/react/ApplicationContext.d.ts +7 -0
- package/esm/shuvi-app/react/{applicationContext.jsx → ApplicationContext.jsx} +0 -0
- package/esm/shuvi-app/react/Error.jsx +4 -1
- package/esm/shuvi-app/react/Link.d.ts +2 -1
- package/esm/shuvi-app/react/Link.jsx +1 -1
- package/esm/shuvi-app/react/getRoutes.d.ts +2 -2
- package/esm/shuvi-app/react/getRoutes.js +9 -8
- package/esm/shuvi-app/react/{redox-react → model}/RedoxWrapper.d.ts +3 -3
- package/esm/shuvi-app/react/{redox-react → model}/RedoxWrapper.jsx +3 -3
- package/esm/shuvi-app/react/model/runtime.d.ts +8 -0
- package/esm/shuvi-app/react/{redox-react → model}/runtime.js +8 -3
- package/esm/shuvi-app/react/store.d.ts +5 -0
- package/esm/shuvi-app/react/store.js +3 -0
- package/esm/shuvi-app/react/types.d.ts +0 -7
- package/esm/shuvi-app/react/useLoaderData.js +9 -20
- package/esm/shuvi-app/react/view/ReactView.client.jsx +34 -23
- package/esm/shuvi-app/react/view/ReactView.server.jsx +29 -14
- package/esm/shuvi-app/react/view/render.d.ts +8 -0
- package/esm/shuvi-app/react/view/{render-action.js → render.js} +6 -6
- package/lib/node/features/custom-server/index.d.ts +1 -1
- package/lib/node/features/custom-server/server.d.ts +1 -1
- package/lib/node/features/custom-server/server.js +20 -11
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +7 -7
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +5 -5
- package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -2
- package/lib/node/features/filesystem-routes/api/middleware.js +5 -2
- package/lib/node/features/filesystem-routes/hooks.d.ts +2 -1
- package/lib/node/features/filesystem-routes/hooks.js +2 -1
- package/lib/node/features/filesystem-routes/index.d.ts +1 -13
- package/lib/node/features/filesystem-routes/index.js +55 -84
- package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -2
- package/lib/node/features/filesystem-routes/middleware/middleware.js +5 -2
- package/lib/node/features/filesystem-routes/page/routes.d.ts +3 -3
- package/lib/node/features/filesystem-routes/page/routes.js +25 -12
- package/lib/node/features/html-render/index.d.ts +4 -18
- package/lib/node/features/html-render/index.js +129 -16
- package/lib/node/features/{main → html-render/lib}/buildHtml.d.ts +0 -0
- package/lib/node/features/{main → html-render/lib}/buildHtml.js +2 -1
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +3 -3
- 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 +12 -8
- package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -2
- package/lib/node/features/html-render/lib/getPageMiddleware.js +18 -13
- package/lib/node/features/html-render/lib/index.d.ts +0 -2
- package/lib/node/features/html-render/lib/index.js +1 -4
- package/lib/node/features/html-render/lib/renderToHTML.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderToHTML.js +9 -49
- package/lib/node/features/html-render/lib/renderer/base.d.ts +7 -8
- package/lib/node/features/html-render/lib/renderer/base.js +19 -11
- package/lib/node/features/html-render/lib/renderer/index.d.ts +5 -4
- package/lib/node/features/html-render/lib/renderer/index.js +77 -8
- package/lib/node/features/html-render/lib/renderer/spa.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderer/spa.js +4 -6
- package/lib/node/features/html-render/lib/renderer/ssr.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderer/ssr.js +9 -11
- package/lib/node/features/html-render/lib/renderer/types.d.ts +10 -8
- package/lib/node/features/html-render/lib/webpack/build-manifest-plugin.d.ts +27 -0
- package/lib/node/features/html-render/lib/webpack/build-manifest-plugin.js +223 -0
- package/lib/node/features/html-render/server.d.ts +1 -1
- package/lib/node/features/html-render/serverHooks.d.ts +6 -1
- package/lib/node/features/html-render/serverHooks.js +1 -2
- package/lib/node/features/index.d.ts +3 -31
- package/lib/node/features/index.js +6 -7
- package/lib/node/features/middlewares.d.ts +1 -1
- package/lib/node/features/middlewares.js +12 -3
- package/lib/node/features/model/index.d.ts +1 -13
- package/lib/node/features/model/runtime.d.ts +3 -8
- package/lib/node/features/model/runtime.js +13 -18
- package/lib/node/features/model/server.js +2 -3
- package/lib/node/features/model/shuvi-app.d.ts +2 -2
- package/lib/node/features/on-demand-compile-page/index.d.ts +3 -13
- package/lib/node/features/on-demand-compile-page/index.js +4 -1
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +3 -3
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +4 -6
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.js +17 -5
- package/lib/node/paths.js +0 -2
- package/lib/node/shuvi-runtime-server.d.ts +26 -0
- package/lib/{shared/serverTypes.js → node/shuvi-runtime-server.js} +0 -0
- package/lib/node/shuvi-type-extensions-node.d.ts +20 -23
- package/lib/node/targets/react/bundler/index.d.ts +1 -13
- package/lib/node/targets/react/bundler/index.js +19 -13
- package/lib/node/targets/react/index.d.ts +2 -27
- package/lib/node/targets/react/index.js +3 -7
- package/lib/node/targets/react/model/index.d.ts +6 -0
- package/lib/node/targets/react/{redox-react → model}/index.js +7 -6
- package/lib/node/version.d.ts +1 -0
- package/lib/node/version.js +13 -0
- package/lib/shared/appTypes.d.ts +12 -6
- package/lib/shared/configTypes.d.ts +1 -3
- package/lib/shared/constants.d.ts +8 -0
- package/lib/shared/constants.js +15 -0
- package/lib/shared/htmlRenderer.d.ts +33 -0
- package/lib/shared/htmlRenderer.js +2 -0
- package/lib/shared/index.d.ts +2 -1
- package/lib/shared/index.js +2 -1
- package/lib/shared/renderTypes.d.ts +8 -7
- package/lib/shared/routeTypes.d.ts +4 -9
- package/package.json +40 -26
- package/polyfills/polyfills.js +1 -0
- 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/shared/serverTypes.d.ts +0 -6
- package/esm/shuvi-app/dev/webpackHotDevClient.d.ts +0 -5
- package/esm/shuvi-app/dev/webpackHotDevClient.js +0 -34
- package/esm/shuvi-app/react/applicationContext.d.ts +0 -7
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +0 -2
- package/esm/shuvi-app/react/view/render-action.d.ts +0 -10
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +0 -4
- package/esm/shuvi-app/shuvi-runtime-index.js +0 -2
- package/esm/shuvi-app/shuvi-runtime-server.d.ts +0 -6
- package/esm/shuvi-app/shuvi-runtime-server.js +0 -1
- package/lib/node/features/html-render/lib/pageLoader.d.ts +0 -1
- package/lib/node/features/html-render/lib/pageLoader.js +0 -42
- package/lib/node/features/main/index.d.ts +0 -3
- package/lib/node/features/main/index.js +0 -82
- package/lib/node/targets/react/redox-react/index.d.ts +0 -18
- package/lib/shared/serverTypes.d.ts +0 -6
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,14 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
9
|
});
|
|
33
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
34
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
15
|
exports.getApiMiddleware = exports.getMiddlewareMiddleware = exports.getRoutes = void 0;
|
|
36
|
-
const fs = __importStar(require("fs"));
|
|
37
|
-
const path = __importStar(require("path"));
|
|
38
|
-
const build_loaders_1 = require("@shuvi/toolpack/lib/utils/build-loaders");
|
|
39
16
|
const service_1 = require("@shuvi/service");
|
|
40
17
|
const node_1 = require("@shuvi/platform-shared/node");
|
|
41
|
-
const
|
|
18
|
+
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
19
|
+
const logger_1 = __importDefault(require("@shuvi/utils/lib/logger"));
|
|
42
20
|
const hooks_1 = require("./hooks");
|
|
43
21
|
const page_1 = require("./page");
|
|
44
22
|
Object.defineProperty(exports, "getRoutes", { enumerable: true, get: function () { return page_1.getRoutes; } });
|
|
@@ -46,13 +24,26 @@ const middleware_1 = require("./middleware");
|
|
|
46
24
|
Object.defineProperty(exports, "getMiddlewareMiddleware", { enumerable: true, get: function () { return middleware_1.middleware; } });
|
|
47
25
|
const api_1 = require("./api");
|
|
48
26
|
Object.defineProperty(exports, "getApiMiddleware", { enumerable: true, get: function () { return api_1.middleware; } });
|
|
27
|
+
let isWarnedAddMiddlewareRoutes = false;
|
|
49
28
|
const plugin = (0, service_1.createPlugin)({
|
|
50
29
|
setup: ({ addHooks }) => {
|
|
51
|
-
addHooks({ addRoutes: hooks_1.addRoutes, addMiddlewareRoutes: hooks_1.addMiddlewareRoutes });
|
|
30
|
+
addHooks({ addRoutes: hooks_1.addRoutes, addApiRoutes: hooks_1.addApiRoutes, addMiddlewareRoutes: hooks_1.addMiddlewareRoutes });
|
|
52
31
|
},
|
|
53
|
-
addRuntimeFile: ({ defineFile }, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
const { config: { routes: pageRoutes,
|
|
32
|
+
addRuntimeFile: ({ defineFile, getContent }, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
const { config: { routes: pageRoutes, conventionRoutes }, paths, pluginRunner, phase, mode } = context;
|
|
55
34
|
const isBuildPhase = phase === 'PHASE_PRODUCTION_BUILD';
|
|
35
|
+
const rawRoutes = defineFile({
|
|
36
|
+
name: 'virtual-raw-routes.js',
|
|
37
|
+
virtual: true,
|
|
38
|
+
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const rawRoutes = yield (0, node_1.getRawRoutesFromDir)(paths.routesDir, conventionRoutes.exclude);
|
|
40
|
+
return rawRoutes;
|
|
41
|
+
}),
|
|
42
|
+
dependencies: [paths.routesDir],
|
|
43
|
+
watchOptions: {
|
|
44
|
+
ignoreFileContentUpdate: true
|
|
45
|
+
}
|
|
46
|
+
});
|
|
56
47
|
const pageRoutesFile = defineFile({
|
|
57
48
|
name: 'routes.js',
|
|
58
49
|
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -62,10 +53,10 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
62
53
|
routes = pageRoutes;
|
|
63
54
|
}
|
|
64
55
|
else {
|
|
65
|
-
const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(
|
|
56
|
+
const { routes: _routes, warnings } = yield (0, node_1.getPageRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
|
|
66
57
|
if (isBuildPhase) {
|
|
67
58
|
warnings.forEach(warning => {
|
|
68
|
-
|
|
59
|
+
logger_1.default.warn(warning.msg);
|
|
69
60
|
});
|
|
70
61
|
}
|
|
71
62
|
routes = _routes;
|
|
@@ -75,57 +66,51 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
75
66
|
// user routes come later
|
|
76
67
|
extraRoutes.concat(routes), paths.routesDir);
|
|
77
68
|
(0, page_1.setRoutes)(normalizedRoutes);
|
|
78
|
-
return (0, page_1.generateRoutesContent)(normalizedRoutes);
|
|
69
|
+
return (0, page_1.generateRoutesContent)(normalizedRoutes, mode === 'development');
|
|
79
70
|
}),
|
|
80
|
-
dependencies: [
|
|
71
|
+
dependencies: [rawRoutes]
|
|
81
72
|
});
|
|
82
73
|
const apiRoutesFile = defineFile({
|
|
83
74
|
name: 'apiRoutes.js',
|
|
84
75
|
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
else {
|
|
91
|
-
const { routes: _routes, warnings } = yield (0, node_1.getApiRoutes)(paths.routesDir, conventionRoutes.exclude);
|
|
92
|
-
if (isBuildPhase) {
|
|
93
|
-
warnings.forEach(warning => {
|
|
94
|
-
console.warn(warning);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
routes = _routes;
|
|
76
|
+
const { routes: fsRoutes, warnings } = yield (0, node_1.getApiRoutes)(getContent(rawRoutes), conventionRoutes.exclude);
|
|
77
|
+
if (isBuildPhase) {
|
|
78
|
+
warnings.forEach(warning => {
|
|
79
|
+
logger_1.default.warn(warning);
|
|
80
|
+
});
|
|
98
81
|
}
|
|
99
|
-
|
|
82
|
+
const pluginRoutes = (yield pluginRunner.addApiRoutes()).flat();
|
|
83
|
+
return (0, api_1.generateRoutesContent)(pluginRoutes.concat(fsRoutes), paths.routesDir);
|
|
100
84
|
}),
|
|
101
|
-
dependencies: [
|
|
85
|
+
dependencies: [rawRoutes]
|
|
102
86
|
});
|
|
103
87
|
const middlewareRoutesFile = defineFile({
|
|
104
88
|
name: 'middlewareRoutes.js',
|
|
105
89
|
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
90
|
+
// Remove the 'middleware' file convention first, and deal with it in a future major update.
|
|
91
|
+
// const { routes: _routes, warnings } = await getMiddlewareRoutes(
|
|
92
|
+
// getContent(rawRoutes),
|
|
93
|
+
// conventionRoutes.exclude
|
|
94
|
+
// );
|
|
95
|
+
// if (isBuildPhase) {
|
|
96
|
+
// warnings.forEach(warning => {
|
|
97
|
+
// logger.warn(warning);
|
|
98
|
+
// });
|
|
99
|
+
// }
|
|
100
|
+
// let fsRoutes = _routes;
|
|
101
|
+
const pluginRoutes = (yield pluginRunner.addMiddlewareRoutes()).flat();
|
|
102
|
+
if (!isWarnedAddMiddlewareRoutes && pluginRoutes.length > 0) {
|
|
103
|
+
logger_1.default.warn('Warning: addMiddlewareRoutes is an experimental feature, we recommend using api routes instead.');
|
|
104
|
+
isWarnedAddMiddlewareRoutes = true;
|
|
119
105
|
}
|
|
120
|
-
|
|
121
|
-
return (0, middleware_1.generateRoutesContent)(extraRoutes.concat(routes), {
|
|
106
|
+
return (0, middleware_1.generateRoutesContent)(pluginRoutes, {
|
|
122
107
|
baseDir: paths.routesDir
|
|
123
108
|
});
|
|
124
109
|
}),
|
|
125
|
-
dependencies: [
|
|
110
|
+
dependencies: [rawRoutes]
|
|
126
111
|
});
|
|
127
|
-
const
|
|
128
|
-
name: 'loaders.js',
|
|
112
|
+
const pageLoadersFile = defineFile({
|
|
113
|
+
name: 'page-loaders.js',
|
|
129
114
|
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
115
|
const routes = (0, page_1.getRoutes)();
|
|
131
116
|
const loaders = {};
|
|
@@ -133,10 +118,7 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
133
118
|
routes.forEach(r => {
|
|
134
119
|
const { component, id, children } = r;
|
|
135
120
|
if (component && id) {
|
|
136
|
-
|
|
137
|
-
if (hasLoader) {
|
|
138
|
-
loaders[id] = component;
|
|
139
|
-
}
|
|
121
|
+
loaders[id] = component;
|
|
140
122
|
}
|
|
141
123
|
if (children) {
|
|
142
124
|
traverseRoutes(children);
|
|
@@ -148,29 +130,18 @@ const plugin = (0, service_1.createPlugin)({
|
|
|
148
130
|
let exports = '';
|
|
149
131
|
Object.entries(loaders).forEach((loader, index) => {
|
|
150
132
|
const [id, component] = loader;
|
|
151
|
-
imports += `import { loader as loader_${index} } from '${component}'\n`;
|
|
133
|
+
imports += `import { loader as loader_${index} } from '${component}?${constants_1.LOADER_RESOURCE_QUERYSTRING}'\n`;
|
|
152
134
|
exports += `'${id}': loader_${index},\n`;
|
|
153
135
|
});
|
|
154
136
|
return `${imports} export default {\n ${exports}\n}`;
|
|
155
137
|
}),
|
|
156
138
|
dependencies: [pageRoutesFile]
|
|
157
139
|
});
|
|
158
|
-
const loadersFileName = path.join(context.paths.appDir, 'files', 'loaders.js');
|
|
159
|
-
const pageLoadersFile = defineFile({
|
|
160
|
-
name: 'page-loaders.js',
|
|
161
|
-
content: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
-
if (fs.existsSync(loadersFileName)) {
|
|
163
|
-
return yield (0, build_loaders_1.buildToString)(loadersFileName);
|
|
164
|
-
}
|
|
165
|
-
return '';
|
|
166
|
-
}),
|
|
167
|
-
dependencies: [loadersFile]
|
|
168
|
-
});
|
|
169
140
|
return [
|
|
141
|
+
rawRoutes,
|
|
170
142
|
pageRoutesFile,
|
|
171
143
|
apiRoutesFile,
|
|
172
144
|
middlewareRoutesFile,
|
|
173
|
-
loadersFile,
|
|
174
145
|
pageLoadersFile
|
|
175
146
|
];
|
|
176
147
|
})
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { IServerPluginContext,
|
|
2
|
-
export declare function middleware(_api: IServerPluginContext):
|
|
1
|
+
import { IServerPluginContext, ShuviRequestHandler } from '@shuvi/service';
|
|
2
|
+
export declare function middleware(_api: IServerPluginContext): ShuviRequestHandler;
|
|
@@ -8,14 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.middleware = void 0;
|
|
13
16
|
const router_1 = require("@shuvi/router");
|
|
14
|
-
const resources_1 = require("@shuvi/service/lib/resources");
|
|
17
|
+
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
15
18
|
function middleware(_api) {
|
|
16
19
|
return function (req, res, next) {
|
|
17
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
const { middlewareRoutes = [] } = resources_1.server;
|
|
21
|
+
const { middlewareRoutes = [] } = resources_1.default.server;
|
|
19
22
|
// match path for get middlewares
|
|
20
23
|
let middlewares = [];
|
|
21
24
|
for (let i = 0; i < middlewareRoutes.length; i++) {
|
|
@@ -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[], includeMeta: boolean): string;
|
|
7
7
|
export declare function normalizeRoutes(routes: IPageRouteConfig[], componentDir: string, parentPath?: string): IPageRouteConfigWithId[];
|
|
8
|
-
export declare const generateRoutesContent: (routes: IPageRouteConfigWithId[]) => string;
|
|
8
|
+
export declare const generateRoutesContent: (routes: IPageRouteConfigWithId[], isDev: boolean) => string;
|
|
@@ -19,9 +19,9 @@ function genRouteId(filepath) {
|
|
|
19
19
|
return (0, crypto_1.createHash)('md4').update(filepath).digest('hex').substr(0, 4);
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* returns JSON string of
|
|
22
|
+
* returns JSON string of IPageRouteConfigWithId
|
|
23
23
|
*/
|
|
24
|
-
function serializeRoutes(routes) {
|
|
24
|
+
function serializeRoutes(routes, includeMeta) {
|
|
25
25
|
let res = '';
|
|
26
26
|
for (let index = 0; index < routes.length; index++) {
|
|
27
27
|
const _a = routes[index], { children: childRoutes } = _a, route = __rest(_a, ["children"]);
|
|
@@ -33,16 +33,18 @@ function serializeRoutes(routes) {
|
|
|
33
33
|
if (key === 'component') {
|
|
34
34
|
const { component } = route;
|
|
35
35
|
const componentSource = component;
|
|
36
|
-
const
|
|
36
|
+
const componentRequest = `${componentSource}?${constants_1.ROUTE_RESOURCE_QUERYSTRING}`;
|
|
37
37
|
// `webpackExports` works with production and optimization.minimize, check compiled dist
|
|
38
|
-
|
|
39
|
-
`
|
|
40
|
-
__componentSource__: "${componentSource}"
|
|
38
|
+
if (includeMeta) {
|
|
39
|
+
strRoute += `__componentRawRequest__: "${componentRequest}",\n`;
|
|
40
|
+
strRoute += `__componentSource__: "${componentSource}",\n`;
|
|
41
|
+
}
|
|
42
|
+
strRoute += `
|
|
41
43
|
__import__: () => import(
|
|
42
44
|
/* webpackChunkName: "page-${id}" */
|
|
43
45
|
/* webpackExports: "default" */
|
|
44
|
-
"${
|
|
45
|
-
__resolveWeak__: () => [require.resolveWeak("${
|
|
46
|
+
"${componentRequest}"),
|
|
47
|
+
__resolveWeak__: () => [require.resolveWeak("${componentRequest}")]`.trim();
|
|
46
48
|
}
|
|
47
49
|
else {
|
|
48
50
|
strRoute += `${key}: ${JSON.stringify(route[key])}`;
|
|
@@ -50,7 +52,7 @@ __resolveWeak__: () => [require.resolveWeak("${componentSourceWithAffix}")]`.tri
|
|
|
50
52
|
strRoute += `,\n`;
|
|
51
53
|
}
|
|
52
54
|
if (childRoutes && childRoutes.length > 0) {
|
|
53
|
-
strRoute += `children: ${serializeRoutes(childRoutes)},\n`;
|
|
55
|
+
strRoute += `children: ${serializeRoutes(childRoutes, includeMeta)},\n`;
|
|
54
56
|
}
|
|
55
57
|
res += `{${strRoute}},\n`;
|
|
56
58
|
}
|
|
@@ -76,8 +78,19 @@ function normalizeRoutes(routes, componentDir, parentPath = '') {
|
|
|
76
78
|
return res;
|
|
77
79
|
}
|
|
78
80
|
exports.normalizeRoutes = normalizeRoutes;
|
|
79
|
-
const generateRoutesContent = (routes) => {
|
|
80
|
-
const
|
|
81
|
-
|
|
81
|
+
const generateRoutesContent = (routes, isDev) => {
|
|
82
|
+
const serverRoutes = serializeRoutes(routes, true);
|
|
83
|
+
const clientRoutes = serializeRoutes(routes, isDev);
|
|
84
|
+
return `
|
|
85
|
+
let routes;
|
|
86
|
+
|
|
87
|
+
if (typeof window === 'undefined') {
|
|
88
|
+
routes = ${serverRoutes}
|
|
89
|
+
} else {
|
|
90
|
+
routes = ${clientRoutes}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export default routes
|
|
94
|
+
`;
|
|
82
95
|
};
|
|
83
96
|
exports.generateRoutesContent = generateRoutesContent;
|
|
@@ -1,19 +1,5 @@
|
|
|
1
|
+
import { ResolvedPlugin } from '@shuvi/service';
|
|
2
|
+
import { IPlatformContext } from '@shuvi/service/lib/core';
|
|
1
3
|
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;
|
|
4
|
+
/** This plugin uses `platformContext` so that it is set to a plugin getter */
|
|
5
|
+
export declare const getPlugin: (platformContext: IPlatformContext) => ResolvedPlugin;
|
|
@@ -1,28 +1,141 @@
|
|
|
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 config_1 = require("@shuvi/toolpack/lib/webpack/config");
|
|
18
|
+
const copy_file_plugin_1 = require("@shuvi/toolpack/lib/webpack/plugins/copy-file-plugin");
|
|
19
|
+
const shared_1 = require("../../../shared");
|
|
8
20
|
const paths_1 = require("../../paths");
|
|
21
|
+
const version_1 = require("../../version");
|
|
22
|
+
const middlewares_1 = require("../middlewares");
|
|
23
|
+
const generateResource_1 = __importDefault(require("./lib/generateResource"));
|
|
24
|
+
const buildHtml_1 = require("./lib/buildHtml");
|
|
25
|
+
const build_manifest_plugin_1 = __importDefault(require("./lib/webpack/build-manifest-plugin"));
|
|
9
26
|
const server_1 = __importDefault(require("./server"));
|
|
27
|
+
const ENTRY_FLAG = 'shuviEntry';
|
|
28
|
+
function makeEntryRequest(req) {
|
|
29
|
+
return `${req}?${ENTRY_FLAG}=true`;
|
|
30
|
+
}
|
|
31
|
+
function getClientEntry() {
|
|
32
|
+
return {
|
|
33
|
+
[shared_1.BUILD_CLIENT_RUNTIME_MAIN]: [
|
|
34
|
+
makeEntryRequest((0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/client'))
|
|
35
|
+
]
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getServerEntry() {
|
|
39
|
+
return {
|
|
40
|
+
[shared_1.BUILD_SERVER_FILE_SERVER]: [
|
|
41
|
+
makeEntryRequest((0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/server'))
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
}
|
|
10
45
|
var lib_1 = require("./lib");
|
|
11
46
|
Object.defineProperty(exports, "getPageMiddleware", { enumerable: true, get: function () { return lib_1.getPageMiddleware; } });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
47
|
+
/** This plugin uses `platformContext` so that it is set to a plugin getter */
|
|
48
|
+
const getPlugin = (platformContext) => {
|
|
49
|
+
const core = (0, service_1.createPlugin)({
|
|
50
|
+
configWebpack: (chain, { name, mode }) => {
|
|
51
|
+
const isDev = mode === 'development';
|
|
52
|
+
const pkgVersion = (0, version_1.getVersion)();
|
|
53
|
+
const isServer = name === shared_1.BUNDLER_TARGET_SERVER;
|
|
54
|
+
const isClient = name === shared_1.BUNDLER_TARGET_CLIENT;
|
|
55
|
+
if (isClient) {
|
|
56
|
+
chain.merge({
|
|
57
|
+
entry: getClientEntry()
|
|
58
|
+
});
|
|
59
|
+
chain.optimization.runtimeChunk({ name: shared_1.BUILD_CLIENT_RUNTIME_WEBPACK });
|
|
60
|
+
chain.plugin('polyfills').use(copy_file_plugin_1.CopyFilePlugin, [
|
|
61
|
+
{
|
|
62
|
+
filePath: (0, paths_1.resolvePkgFile)('polyfills/polyfills.js'),
|
|
63
|
+
cacheKey: pkgVersion,
|
|
64
|
+
name: shared_1.BUILD_CLIENT_RUNTIME_POLYFILLS,
|
|
65
|
+
info: {
|
|
66
|
+
[shared_1.BUILD_CLIENT_RUNTIME_POLYFILLS_SYMBOL]: 1,
|
|
67
|
+
// This file is already minified
|
|
68
|
+
minimized: true
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
]);
|
|
72
|
+
chain.plugin('private/build-manifest').use(build_manifest_plugin_1.default, [
|
|
73
|
+
{
|
|
74
|
+
filename: shared_1.CLIENT_BUILD_MANIFEST_PATH,
|
|
75
|
+
modules: true,
|
|
76
|
+
chunkRequest: isDev
|
|
77
|
+
}
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
else if (isServer) {
|
|
81
|
+
chain.plugin('private/build-manifest').use(build_manifest_plugin_1.default, [
|
|
82
|
+
{
|
|
83
|
+
filename: shared_1.SERVER_BUILD_MANIFEST_PATH,
|
|
84
|
+
modules: false,
|
|
85
|
+
chunkRequest: isDev
|
|
86
|
+
}
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
return chain;
|
|
90
|
+
},
|
|
91
|
+
addExtraTarget: ({ createConfig }, context) => {
|
|
92
|
+
const serverWebpackHelpers = (0, config_1.webpackHelpers)();
|
|
93
|
+
const serverChain = createConfig({
|
|
94
|
+
name: shared_1.BUNDLER_TARGET_SERVER,
|
|
95
|
+
node: true,
|
|
96
|
+
entry: getServerEntry(),
|
|
97
|
+
outputDir: shared_1.SERVER_OUTPUT_DIR,
|
|
98
|
+
webpackHelpers: serverWebpackHelpers
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
name: shared_1.BUNDLER_TARGET_SERVER,
|
|
102
|
+
chain: serverChain
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
addRuntimeFile: ({ defineFile }, context) => {
|
|
106
|
+
const { config: { router: { history } } } = context;
|
|
107
|
+
const routerConfigFile = defineFile({
|
|
108
|
+
name: 'routerConfig.js',
|
|
109
|
+
content: () => {
|
|
110
|
+
return `export const historyMode = "${history}";`;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
return [routerConfigFile];
|
|
114
|
+
},
|
|
115
|
+
addRuntimeService: () => [
|
|
116
|
+
{
|
|
117
|
+
source: (0, paths_1.resolvePkgFile)('lib/node/shuvi-runtime-server'),
|
|
118
|
+
filepath: 'server.ts',
|
|
119
|
+
exported: '*'
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
addResource: context => (0, generateResource_1.default)(context),
|
|
123
|
+
afterBuild: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
|
+
if (context.config.ssr === false) {
|
|
125
|
+
yield (0, buildHtml_1.buildHtml)({
|
|
126
|
+
context,
|
|
127
|
+
serverPlugins: platformContext.serverPlugins,
|
|
128
|
+
getMiddlewares: middlewares_1.getMiddlewares,
|
|
129
|
+
pathname: '/',
|
|
130
|
+
filename: 'index.html'
|
|
131
|
+
});
|
|
19
132
|
}
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
types: (0, paths_1.resolvePkgFile)('lib/node/features/html-render/shuvi-app.d.ts')
|
|
133
|
+
})
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
core,
|
|
137
|
+
server: server_1.default,
|
|
138
|
+
types: (0, paths_1.resolvePkgFile)('lib/node/features/html-render/shuvi-app.d.ts')
|
|
139
|
+
};
|
|
28
140
|
};
|
|
141
|
+
exports.getPlugin = getPlugin;
|
|
File without changes
|
|
@@ -38,6 +38,7 @@ const fse = __importStar(require("fs-extra"));
|
|
|
38
38
|
const node_mocks_http_1 = require("node-mocks-http");
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
40
|
const service_1 = require("@shuvi/service");
|
|
41
|
+
const shared_1 = require("../../../../shared");
|
|
41
42
|
const buildHtml = ({ context, serverPlugins, getMiddlewares, pathname, filename }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
43
|
return new Promise(resolve => {
|
|
43
44
|
const request = (0, node_mocks_http_1.createRequest)({
|
|
@@ -48,7 +49,7 @@ const buildHtml = ({ context, serverPlugins, getMiddlewares, pathname, filename
|
|
|
48
49
|
});
|
|
49
50
|
response.on('end', () => {
|
|
50
51
|
const html = response._getBuffer();
|
|
51
|
-
fse.writeFileSync(path.resolve(context.paths.buildDir,
|
|
52
|
+
fse.writeFileSync(path.resolve(context.paths.buildDir, shared_1.CLIENT_OUTPUT_DIR, filename), html);
|
|
52
53
|
resolve();
|
|
53
54
|
});
|
|
54
55
|
(0, service_1.createShuviServer)({
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export default function generateFilesByRoutId(assetMap: IManifest, routes:
|
|
1
|
+
import { IPageRouteRecord } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { IManifest } from '../../../../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
|
|
@@ -25,30 +25,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const path = __importStar(require("path"));
|
|
27
27
|
const fse = __importStar(require("fs-extra"));
|
|
28
|
-
const service_1 = require("@shuvi/service");
|
|
29
28
|
const file_utils_1 = require("@shuvi/service/lib/project/file-utils");
|
|
29
|
+
const shared_1 = require("../../../../shared");
|
|
30
30
|
const generateResources = (context) => {
|
|
31
|
-
const { resolveUserFile } = context;
|
|
31
|
+
const { resolveUserFile, paths } = context;
|
|
32
|
+
const resourcesDir = path.dirname(paths.resourcesFile);
|
|
32
33
|
const { buildDir } = context.paths;
|
|
33
|
-
const clientManifestRequest = (0, file_utils_1.urlToRequest)(path.join(buildDir,
|
|
34
|
-
const serverManifestRequest = (0, file_utils_1.urlToRequest)(path.join(buildDir,
|
|
35
|
-
const serverModuleDir = path.join(buildDir,
|
|
34
|
+
const clientManifestRequest = (0, file_utils_1.urlToRequest)(path.relative(resourcesDir, path.join(buildDir, shared_1.CLIENT_OUTPUT_DIR, shared_1.CLIENT_BUILD_MANIFEST_PATH)));
|
|
35
|
+
const serverManifestRequest = (0, file_utils_1.urlToRequest)(path.relative(resourcesDir, path.join(buildDir, shared_1.SERVER_OUTPUT_DIR, shared_1.SERVER_BUILD_MANIFEST_PATH)));
|
|
36
|
+
const serverModuleDir = path.relative(resourcesDir, path.join(buildDir, shared_1.SERVER_OUTPUT_DIR));
|
|
36
37
|
const result = [];
|
|
37
38
|
result.push(['clientManifest', clientManifestRequest]);
|
|
38
39
|
result.push(['serverManifest', serverManifestRequest]);
|
|
39
40
|
result.push([
|
|
40
41
|
`server = function() {
|
|
41
42
|
const path = require('path');
|
|
42
|
-
const relativeModulePath = require('${serverManifestRequest}')['bundles']['${
|
|
43
|
+
const relativeModulePath = require('${serverManifestRequest}')['bundles']['${shared_1.BUILD_SERVER_FILE_SERVER}'];
|
|
43
44
|
const modulePath = require.resolve(path.join("${serverModuleDir}", relativeModulePath));
|
|
44
45
|
return require(modulePath)
|
|
45
46
|
}`,
|
|
46
47
|
undefined
|
|
47
48
|
]);
|
|
48
49
|
const customDoc = resolveUserFile('document.ejs');
|
|
49
|
-
let documentPath
|
|
50
|
+
let documentPath;
|
|
50
51
|
if (fse.existsSync(customDoc)) {
|
|
51
|
-
documentPath = customDoc;
|
|
52
|
+
documentPath = path.relative(process.cwd(), customDoc);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
documentPath = path.relative(process.cwd(), require.resolve('@shuvi/platform-shared/template/document.ejs'));
|
|
52
56
|
}
|
|
53
57
|
result.push([`documentPath = "${documentPath}"`, undefined]);
|
|
54
58
|
return result;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function getPageMiddleware(api: IServerPluginContext):
|
|
1
|
+
import { ShuviRequestHandler, IServerPluginContext } from '@shuvi/service';
|
|
2
|
+
export declare function getPageMiddleware(api: IServerPluginContext): Promise<ShuviRequestHandler>;
|