@shuvi/platform-web 0.0.1-rc.34 → 1.0.0-rc.2
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 +15 -0
- package/esm/shared/appTypes.js +1 -0
- package/esm/shared/configTypes.d.ts +14 -0
- package/esm/shared/configTypes.js +1 -0
- package/esm/shared/index.d.ts +5 -0
- package/esm/shared/index.js +5 -0
- package/esm/shared/renderTypes.d.ts +44 -0
- package/esm/shared/renderTypes.js +1 -0
- package/esm/shared/routeTypes.d.ts +47 -0
- package/esm/shared/routeTypes.js +1 -0
- package/esm/shared/serverTypes.d.ts +6 -0
- package/esm/shared/serverTypes.js +1 -0
- package/esm/shuvi-app/app/client.d.ts +2 -0
- package/esm/shuvi-app/app/client.js +125 -0
- package/esm/shuvi-app/app/server.d.ts +2 -0
- package/esm/shuvi-app/app/server.js +67 -0
- package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.d.ts +0 -0
- package/{shuvi-app → esm/shuvi-app}/dev/webpackHotDevClient.js +2 -1
- package/esm/shuvi-app/entry/client/app.d.ts +2 -0
- package/esm/shuvi-app/entry/client/app.js +57 -0
- package/esm/shuvi-app/entry/client/index.d.ts +2 -0
- package/esm/shuvi-app/entry/client/index.js +12 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.d.ts +0 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.dev.js +2 -2
- package/{shuvi-app → esm/shuvi-app}/entry/client/run.prod.d.ts +0 -0
- package/esm/shuvi-app/entry/client/run.prod.js +3 -0
- package/{shuvi-app → esm/shuvi-app}/entry/client/setup-env.d.ts +1 -1
- package/esm/shuvi-app/entry/client/setup-env.js +17 -0
- package/esm/shuvi-app/entry/server/index.d.ts +6 -0
- package/esm/shuvi-app/entry/server/index.js +7 -0
- package/esm/shuvi-app/react/AppComponent.d.ts +4 -0
- package/esm/shuvi-app/react/AppComponent.jsx +6 -0
- package/esm/shuvi-app/react/AppContainer.d.ts +6 -0
- package/esm/shuvi-app/react/AppContainer.jsx +23 -0
- package/esm/shuvi-app/react/Error.d.ts +5 -0
- package/esm/shuvi-app/react/Error.jsx +38 -0
- package/esm/shuvi-app/react/ErrorBoundary.d.ts +16 -0
- package/esm/shuvi-app/react/ErrorBoundary.jsx +25 -0
- package/esm/shuvi-app/react/ErrorPage.d.ts +5 -0
- package/esm/shuvi-app/react/ErrorPage.jsx +7 -0
- package/esm/shuvi-app/react/Link.d.ts +7 -0
- package/esm/shuvi-app/react/Link.jsx +115 -0
- package/esm/shuvi-app/react/applicationContext.d.ts +7 -0
- package/esm/shuvi-app/react/applicationContext.jsx +10 -0
- package/esm/shuvi-app/react/dynamic.d.ts +31 -0
- package/esm/shuvi-app/react/dynamic.jsx +62 -0
- package/esm/shuvi-app/react/getRoutes.d.ts +2 -0
- package/esm/shuvi-app/react/getRoutes.js +31 -0
- package/esm/shuvi-app/react/head/head-manager-context.d.ts +2 -0
- package/esm/shuvi-app/react/head/head-manager-context.js +2 -0
- package/esm/shuvi-app/react/head/head-manager.d.ts +10 -0
- package/esm/shuvi-app/react/head/head-manager.js +93 -0
- package/esm/shuvi-app/react/head/head.d.ts +33 -0
- package/esm/shuvi-app/react/head/head.jsx +178 -0
- package/esm/shuvi-app/react/head/index.d.ts +4 -0
- package/esm/shuvi-app/react/head/index.js +4 -0
- package/esm/shuvi-app/react/head/side-effect.d.ts +30 -0
- package/esm/shuvi-app/react/head/side-effect.jsx +44 -0
- package/esm/shuvi-app/react/head/types.d.ts +15 -0
- package/esm/shuvi-app/react/head/types.js +1 -0
- package/esm/shuvi-app/react/index.d.ts +4 -0
- package/esm/shuvi-app/react/index.js +4 -0
- package/esm/shuvi-app/react/loadRouteComponent.d.ts +4 -0
- package/esm/shuvi-app/react/loadRouteComponent.jsx +9 -0
- package/esm/shuvi-app/react/loadable/index.d.ts +2 -0
- package/esm/shuvi-app/react/loadable/index.js +2 -0
- package/esm/shuvi-app/react/loadable/loadable-context.d.ts +4 -0
- package/esm/shuvi-app/react/loadable/loadable-context.js +3 -0
- package/esm/shuvi-app/react/loadable/loadable.d.ts +30 -0
- package/esm/shuvi-app/react/loadable/loadable.js +277 -0
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.d.ts +8 -0
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.jsx +11 -0
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +2 -0
- package/esm/shuvi-app/react/redox-react/runtime.js +16 -0
- package/esm/shuvi-app/react/shuvi-runtime-api.d.ts +5 -0
- package/esm/shuvi-app/react/shuvi-runtime-api.js +5 -0
- package/esm/shuvi-app/react/types.d.ts +14 -0
- package/esm/shuvi-app/react/types.js +1 -0
- package/esm/shuvi-app/react/useLoaderData.d.ts +2 -0
- package/esm/shuvi-app/react/useLoaderData.js +27 -0
- package/esm/shuvi-app/react/utils/getDisplayName.d.ts +2 -0
- package/esm/shuvi-app/react/utils/getDisplayName.js +3 -0
- package/esm/shuvi-app/react/utils/requestIdleCallback.d.ts +2 -0
- package/esm/shuvi-app/react/utils/requestIdleCallback.js +20 -0
- package/esm/shuvi-app/react/utils/useIntersection.d.ts +8 -0
- package/esm/shuvi-app/react/utils/useIntersection.jsx +91 -0
- package/esm/shuvi-app/react/view/ReactView.client.d.ts +5 -0
- package/esm/shuvi-app/react/view/ReactView.client.jsx +64 -0
- package/esm/shuvi-app/react/view/ReactView.server.d.ts +4 -0
- package/esm/shuvi-app/react/view/ReactView.server.jsx +109 -0
- package/esm/shuvi-app/react/view/clientView.d.ts +3 -0
- package/esm/shuvi-app/react/view/clientView.js +2 -0
- package/esm/shuvi-app/react/view/index.d.ts +2 -0
- package/esm/shuvi-app/react/view/index.js +7 -0
- package/esm/shuvi-app/react/view/render-action.d.ts +10 -0
- package/esm/shuvi-app/react/view/render-action.js +29 -0
- package/esm/shuvi-app/react/view/serverView.d.ts +3 -0
- package/esm/shuvi-app/react/view/serverView.js +2 -0
- package/esm/shuvi-app/react/view/transformRoutes.d.ts +2 -0
- package/esm/shuvi-app/react/view/transformRoutes.js +3 -0
- package/esm/shuvi-app/shuvi-runtime-index.d.ts +4 -0
- package/esm/shuvi-app/shuvi-runtime-index.js +2 -0
- package/esm/shuvi-app/shuvi-runtime-server.d.ts +6 -0
- package/esm/shuvi-app/shuvi-runtime-server.js +1 -0
- package/lib/node/features/custom-server/index.d.ts +4 -0
- package/lib/node/features/custom-server/index.js +9 -0
- package/lib/node/features/custom-server/server.d.ts +2 -0
- package/lib/node/features/custom-server/server.js +28 -0
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.d.ts +51 -0
- package/lib/node/features/filesystem-routes/api/apiRouteHandler.js +237 -0
- package/lib/node/features/filesystem-routes/api/apiRoutes.d.ts +7 -0
- package/lib/node/features/filesystem-routes/api/apiRoutes.js +35 -0
- package/lib/node/features/filesystem-routes/api/index.d.ts +3 -0
- package/lib/node/features/filesystem-routes/api/index.js +7 -0
- package/lib/node/features/filesystem-routes/api/middleware.d.ts +2 -0
- package/lib/node/features/filesystem-routes/api/middleware.js +44 -0
- package/lib/node/features/filesystem-routes/hooks.d.ts +3 -0
- package/lib/node/features/filesystem-routes/hooks.js +6 -0
- package/lib/node/features/filesystem-routes/index.d.ts +20 -0
- package/lib/node/features/filesystem-routes/index.js +180 -0
- package/lib/node/features/filesystem-routes/middleware/index.d.ts +2 -0
- package/lib/node/features/filesystem-routes/middleware/index.js +7 -0
- package/lib/node/features/filesystem-routes/middleware/middleware.d.ts +2 -0
- package/lib/node/features/filesystem-routes/middleware/middleware.js +42 -0
- package/lib/node/features/filesystem-routes/middleware/routes.d.ts +9 -0
- package/lib/node/features/filesystem-routes/middleware/routes.js +34 -0
- package/lib/node/features/filesystem-routes/page/index.d.ts +2 -0
- package/lib/node/features/filesystem-routes/page/index.js +21 -0
- package/lib/node/features/filesystem-routes/page/routes.d.ts +8 -0
- package/lib/node/features/filesystem-routes/page/routes.js +83 -0
- package/lib/node/features/filesystem-routes/page/store.d.ts +3 -0
- package/lib/node/features/filesystem-routes/page/store.js +10 -0
- package/lib/node/features/html-render/index.d.ts +19 -0
- package/lib/node/features/html-render/index.js +28 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +3 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.js +13 -0
- package/lib/node/features/html-render/lib/getPageMiddleware.d.ts +2 -0
- package/lib/node/features/html-render/lib/getPageMiddleware.js +56 -0
- package/lib/node/features/html-render/lib/index.d.ts +4 -0
- package/lib/node/features/html-render/lib/index.js +23 -0
- package/lib/node/features/html-render/lib/pageLoader.d.ts +1 -0
- package/lib/node/features/html-render/lib/pageLoader.js +42 -0
- package/lib/node/features/html-render/lib/renderToHTML.d.ts +6 -0
- package/lib/node/features/html-render/lib/renderToHTML.js +81 -0
- package/lib/node/features/html-render/lib/renderer/base.d.ts +17 -0
- package/lib/node/features/html-render/lib/renderer/base.js +70 -0
- package/lib/node/features/html-render/lib/renderer/htmlTag.d.ts +4 -0
- package/lib/node/features/html-render/lib/renderer/htmlTag.js +70 -0
- package/lib/node/features/html-render/lib/renderer/index.d.ts +15 -0
- package/lib/node/features/html-render/lib/renderer/index.js +48 -0
- package/lib/node/features/html-render/lib/renderer/spa.d.ts +5 -0
- package/lib/node/features/html-render/lib/renderer/spa.js +26 -0
- package/lib/node/features/html-render/lib/renderer/ssr.d.ts +5 -0
- package/lib/node/features/html-render/lib/renderer/ssr.js +70 -0
- package/lib/node/features/html-render/lib/renderer/types.d.ts +20 -0
- package/lib/node/features/html-render/lib/renderer/types.js +2 -0
- package/lib/node/features/html-render/lib/viewTemplate.d.ts +5 -0
- package/lib/node/features/html-render/lib/viewTemplate.js +37 -0
- package/lib/node/features/html-render/server.d.ts +2 -0
- package/lib/node/features/html-render/server.js +9 -0
- package/lib/node/features/html-render/serverHooks.d.ts +10 -0
- package/lib/node/features/html-render/serverHooks.js +13 -0
- package/lib/node/features/html-render/shuvi-app.d.ts +6 -0
- package/lib/node/features/html-render/shuvi-app.js +2 -0
- package/lib/node/features/index.d.ts +32 -0
- package/lib/node/features/index.js +25 -0
- package/lib/node/features/main/buildHtml.d.ts +8 -0
- package/lib/node/features/main/buildHtml.js +64 -0
- package/lib/node/features/main/generateResource.d.ts +3 -0
- package/lib/node/features/main/generateResource.js +56 -0
- package/lib/node/features/main/index.d.ts +3 -0
- package/lib/node/features/main/index.js +82 -0
- package/lib/node/features/middlewares.d.ts +4 -0
- package/lib/node/features/middlewares.js +23 -0
- package/lib/node/features/model/index.d.ts +21 -0
- package/lib/node/features/model/index.js +54 -0
- package/lib/node/features/model/runtime.d.ts +13 -0
- package/lib/node/features/model/runtime.js +47 -0
- package/lib/node/features/model/server.d.ts +3 -0
- package/lib/node/features/model/server.js +12 -0
- package/lib/node/features/model/shuvi-app.d.ts +6 -0
- package/lib/node/features/model/shuvi-app.js +2 -0
- package/lib/node/features/on-demand-compile-page/emptyComponent.d.ts +1 -0
- package/lib/node/features/on-demand-compile-page/emptyComponent.js +7 -0
- package/lib/node/features/on-demand-compile-page/index.d.ts +15 -0
- package/lib/node/features/on-demand-compile-page/index.js +36 -0
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.d.ts +11 -0
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +104 -0
- package/lib/node/index.d.ts +6 -0
- package/lib/node/index.js +38 -0
- package/lib/{paths.d.ts → node/paths.d.ts} +1 -2
- package/lib/node/paths.js +36 -0
- package/lib/node/shuvi-type-extensions-node.d.ts +42 -0
- package/lib/node/shuvi-type-extensions-node.js +3 -0
- package/lib/node/targets/react/bundler/index.d.ts +16 -0
- package/lib/node/targets/react/bundler/index.js +102 -0
- package/lib/node/targets/react/index.d.ts +32 -0
- package/lib/node/targets/react/index.js +28 -0
- package/lib/node/targets/react/redox-react/index.d.ts +18 -0
- package/lib/node/targets/react/redox-react/index.js +50 -0
- package/lib/shared/appTypes.d.ts +15 -0
- package/lib/shared/appTypes.js +2 -0
- package/lib/shared/configTypes.d.ts +14 -0
- package/lib/shared/configTypes.js +2 -0
- package/lib/shared/index.d.ts +5 -0
- package/lib/shared/index.js +21 -0
- package/lib/shared/renderTypes.d.ts +44 -0
- package/lib/shared/renderTypes.js +2 -0
- package/lib/shared/routeTypes.d.ts +47 -0
- package/lib/shared/routeTypes.js +2 -0
- package/lib/shared/serverTypes.d.ts +6 -0
- package/lib/shared/serverTypes.js +2 -0
- package/package.json +78 -15
- package/shuvi-type-extensions-node.d.ts +2 -0
- package/shuvi-type-extensions-runtime.d.ts +36 -0
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -44
- package/lib/paths.js +0 -7
- package/shuvi-app/application/client/create-application-factory.d.ts +0 -3
- package/shuvi-app/application/client/create-application-factory.js +0 -70
- package/shuvi-app/application/client/create-application-history-browser.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-browser.js +0 -3
- package/shuvi-app/application/client/create-application-history-hash.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-hash.js +0 -3
- package/shuvi-app/application/client/create-application-history-memory.d.ts +0 -1
- package/shuvi-app/application/client/create-application-history-memory.js +0 -3
- package/shuvi-app/application/server/create-application-spa.d.ts +0 -2
- package/shuvi-app/application/server/create-application-spa.js +0 -8
- package/shuvi-app/application/server/create-application.d.ts +0 -2
- package/shuvi-app/application/server/create-application.js +0 -25
- package/shuvi-app/entry/client/index.d.ts +0 -1
- package/shuvi-app/entry/client/index.js +0 -11
- package/shuvi-app/entry/client/run.prod.js +0 -3
- package/shuvi-app/entry/client/setup-app.d.ts +0 -3
- package/shuvi-app/entry/client/setup-app.js +0 -38
- package/shuvi-app/entry/client/setup-env.js +0 -27
- package/shuvi-app/entry/server/index.d.ts +0 -6
- package/shuvi-app/entry/server/index.js +0 -7
|
@@ -0,0 +1,48 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Renderer = void 0;
|
|
18
|
+
const resources_1 = require("@shuvi/service/lib/resources");
|
|
19
|
+
const htmlTag_1 = require("./htmlTag");
|
|
20
|
+
const viewTemplate_1 = require("../viewTemplate");
|
|
21
|
+
const spa_1 = require("./spa");
|
|
22
|
+
const ssr_1 = require("./ssr");
|
|
23
|
+
__exportStar(require("./types"), exports);
|
|
24
|
+
class Renderer {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this._serverPluginContext = options.serverPluginContext;
|
|
27
|
+
this._documentTemplate = (0, viewTemplate_1.parseTemplateFile)(resources_1.documentPath);
|
|
28
|
+
this._ssrRenderer = new ssr_1.SsrRenderer(options);
|
|
29
|
+
this._spaRenderer = new spa_1.SpaRenderer(options);
|
|
30
|
+
}
|
|
31
|
+
renderDocument(options) {
|
|
32
|
+
if (this._serverPluginContext.config.ssr) {
|
|
33
|
+
return this._ssrRenderer.renderDocument(options);
|
|
34
|
+
}
|
|
35
|
+
return this._spaRenderer.renderDocument(options);
|
|
36
|
+
}
|
|
37
|
+
renderDocumentToString(document, templateData = {}) {
|
|
38
|
+
const htmlAttrs = (0, htmlTag_1.stringifyAttrs)(document.htmlAttrs);
|
|
39
|
+
const head = document.headTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
|
|
40
|
+
const main = document.mainTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
|
|
41
|
+
const script = document.scriptTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
|
|
42
|
+
return (0, viewTemplate_1.renderTemplate)(this._documentTemplate, Object.assign({ htmlAttrs,
|
|
43
|
+
head,
|
|
44
|
+
main,
|
|
45
|
+
script }, templateData));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.Renderer = Renderer;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpaRenderer = void 0;
|
|
4
|
+
const base_1 = require("./base");
|
|
5
|
+
class SpaRenderer extends base_1.BaseRenderer {
|
|
6
|
+
renderDocument({ app }) {
|
|
7
|
+
const assets = this._getMainAssetTags();
|
|
8
|
+
const serverPluginContext = this._serverPluginContext;
|
|
9
|
+
const appData = {
|
|
10
|
+
pageData: {},
|
|
11
|
+
ssr: serverPluginContext.config.ssr,
|
|
12
|
+
loadersData: {}
|
|
13
|
+
};
|
|
14
|
+
const document = {
|
|
15
|
+
htmlAttrs: {},
|
|
16
|
+
headTags: [...assets.styles],
|
|
17
|
+
mainTags: [
|
|
18
|
+
this._getInlineAppData(app, appData),
|
|
19
|
+
this._getAppContainerTag()
|
|
20
|
+
],
|
|
21
|
+
scriptTags: [...assets.scripts]
|
|
22
|
+
};
|
|
23
|
+
return document;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.SpaRenderer = SpaRenderer;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { BaseRenderer } from './base';
|
|
2
|
+
import { IHtmlDocument, IRenderDocumentOptions } from './types';
|
|
3
|
+
export declare class SsrRenderer extends BaseRenderer {
|
|
4
|
+
renderDocument({ app, req }: IRenderDocumentOptions): Promise<import("@shuvi/platform-shared/shared").Response | IHtmlDocument>;
|
|
5
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SsrRenderer = void 0;
|
|
13
|
+
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
14
|
+
const shuvi_singleton_runtimeConfig_1 = require("@shuvi/platform-shared/shared/shuvi-singleton-runtimeConfig");
|
|
15
|
+
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
16
|
+
const resources_1 = require("@shuvi/service/lib/resources");
|
|
17
|
+
const base_1 = require("./base");
|
|
18
|
+
const htmlTag_1 = require("./htmlTag");
|
|
19
|
+
class SsrRenderer extends base_1.BaseRenderer {
|
|
20
|
+
renderDocument({ app, req }) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const { router, context } = app;
|
|
23
|
+
const serverPluginContext = this._serverPluginContext;
|
|
24
|
+
const { view } = resources_1.server;
|
|
25
|
+
const { getAssetPublicUrl } = serverPluginContext;
|
|
26
|
+
if (!router) {
|
|
27
|
+
throw new Error('router is null');
|
|
28
|
+
}
|
|
29
|
+
const result = yield view.renderApp({
|
|
30
|
+
app,
|
|
31
|
+
req,
|
|
32
|
+
manifest: resources_1.clientManifest,
|
|
33
|
+
getAssetPublicUrl
|
|
34
|
+
});
|
|
35
|
+
if ((0, shared_1.isResponse)(result)) {
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
const mainAssetsTags = this._getMainAssetTags();
|
|
39
|
+
const pageDataList = yield serverPluginContext.serverPluginRunner.getPageData(context);
|
|
40
|
+
const pageData = pageDataList.reduce((acc, data) => {
|
|
41
|
+
Object.assign(acc, data);
|
|
42
|
+
return acc;
|
|
43
|
+
}, {});
|
|
44
|
+
const appData = Object.assign(Object.assign({}, result.appData), { pageData, ssr: serverPluginContext.config.ssr });
|
|
45
|
+
appData.runtimeConfig = (0, shuvi_singleton_runtimeConfig_1.getPublicRuntimeConfig)() || {};
|
|
46
|
+
const document = {
|
|
47
|
+
htmlAttrs: Object.assign({}, result.htmlAttrs),
|
|
48
|
+
headTags: [
|
|
49
|
+
...(result.headBeginTags || []),
|
|
50
|
+
...mainAssetsTags.styles,
|
|
51
|
+
...(result.headEndTags || [])
|
|
52
|
+
],
|
|
53
|
+
mainTags: [
|
|
54
|
+
this._getInlineAppData(app, appData),
|
|
55
|
+
...(result.mainBeginTags || []),
|
|
56
|
+
this._getAppContainerTag(result.content),
|
|
57
|
+
...(result.mainEndTags || [])
|
|
58
|
+
],
|
|
59
|
+
scriptTags: [
|
|
60
|
+
(0, htmlTag_1.tag)('script', {}, `${constants_1.IDENTITY_RUNTIME_PUBLICPATH} = "${serverPluginContext.assetPublicPath}"`),
|
|
61
|
+
...(result.scriptBeginTags || []),
|
|
62
|
+
...mainAssetsTags.scripts,
|
|
63
|
+
...(result.scriptEndTags || [])
|
|
64
|
+
]
|
|
65
|
+
};
|
|
66
|
+
return document;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.SsrRenderer = SsrRenderer;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { IApplication, IRequest } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { IHtmlAttrs, IHtmlTag, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer, IRenderAppServerResult } from '../../../../../shared';
|
|
3
|
+
import { IServerPluginContext } from '@shuvi/service';
|
|
4
|
+
export { IHtmlAttrs, IHtmlTag, IApplication };
|
|
5
|
+
export interface IRendererConstructorOptions {
|
|
6
|
+
serverPluginContext: IServerPluginContext;
|
|
7
|
+
}
|
|
8
|
+
export declare type IRenderDocumentOptions = {
|
|
9
|
+
app: IApplication;
|
|
10
|
+
req: IRequest;
|
|
11
|
+
};
|
|
12
|
+
export interface IHtmlDocument {
|
|
13
|
+
htmlAttrs: IHtmlAttrs;
|
|
14
|
+
headTags: IHtmlTag<'meta' | 'link' | 'style' | 'script' | 'noscript' | 'title'>[];
|
|
15
|
+
mainTags: IHtmlTag[];
|
|
16
|
+
scriptTags: IHtmlTag<'script'>[];
|
|
17
|
+
}
|
|
18
|
+
export interface IRenderOptions extends IRenderDocumentOptions {
|
|
19
|
+
}
|
|
20
|
+
export { IRenderAppServerResult, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TemplateFunction } from 'ejs';
|
|
2
|
+
export { TemplateFunction };
|
|
3
|
+
declare function parseTemplateFile(templateFile: string): TemplateFunction;
|
|
4
|
+
declare function renderTemplate(templateFn: TemplateFunction, data: any): string;
|
|
5
|
+
export { parseTemplateFile, renderTemplate };
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.renderTemplate = exports.parseTemplateFile = void 0;
|
|
27
|
+
const ejs = __importStar(require("ejs"));
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
function parseTemplateFile(templateFile) {
|
|
30
|
+
const content = fs.readFileSync(templateFile, 'utf8');
|
|
31
|
+
return ejs.compile(content);
|
|
32
|
+
}
|
|
33
|
+
exports.parseTemplateFile = parseTemplateFile;
|
|
34
|
+
function renderTemplate(templateFn, data) {
|
|
35
|
+
return templateFn(data);
|
|
36
|
+
}
|
|
37
|
+
exports.renderTemplate = renderTemplate;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/service/lib/server/pluginTypes").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
|
|
2
|
+
export default _default;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const service_1 = require("@shuvi/service");
|
|
4
|
+
const serverHooks_1 = require("./serverHooks");
|
|
5
|
+
exports.default = (0, service_1.createServerPlugin)({
|
|
6
|
+
setup: ({ addHooks }) => {
|
|
7
|
+
addHooks(serverHooks_1.extendedHooks);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { IAppContext } from '@shuvi/platform-shared/shared';
|
|
4
|
+
import { IHtmlDocument } from '../html-render';
|
|
5
|
+
export declare type IHandlePageRequest = (req: IncomingMessage, res: ServerResponse) => any;
|
|
6
|
+
export declare const extendedHooks: {
|
|
7
|
+
getPageData: import("@shuvi/hook").AsyncParallelHook<void, IAppContext, Record<string, unknown>>;
|
|
8
|
+
handlePageRequest: import("@shuvi/hook").SyncWaterfallHook<IHandlePageRequest, void>;
|
|
9
|
+
modifyHtml: import("@shuvi/hook").AsyncParallelHook<IHtmlDocument, IAppContext, void>;
|
|
10
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extendedHooks = void 0;
|
|
4
|
+
const hook_1 = require("@shuvi/hook");
|
|
5
|
+
const getPageData = (0, hook_1.createAsyncParallelHook)();
|
|
6
|
+
const handlePageRequest = (0, hook_1.createSyncWaterfallHook)();
|
|
7
|
+
// todo: change to AsyncSeries
|
|
8
|
+
const modifyHtml = (0, hook_1.createAsyncParallelHook)();
|
|
9
|
+
exports.extendedHooks = {
|
|
10
|
+
getPageData,
|
|
11
|
+
handlePageRequest,
|
|
12
|
+
modifyHtml
|
|
13
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { buildHtml } from './main/buildHtml';
|
|
2
|
+
export { getMiddlewares, getMiddlewaresBeforeDevMiddlewares } from './middlewares';
|
|
3
|
+
export { getPlugin as getMainPlugin } from './main';
|
|
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
|
+
})[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.featurePlugins = exports.getMainPlugin = exports.getMiddlewaresBeforeDevMiddlewares = exports.getMiddlewares = exports.buildHtml = void 0;
|
|
7
|
+
const on_demand_compile_page_1 = __importDefault(require("./on-demand-compile-page"));
|
|
8
|
+
const html_render_1 = __importDefault(require("./html-render"));
|
|
9
|
+
const custom_server_1 = __importDefault(require("./custom-server"));
|
|
10
|
+
const model_1 = __importDefault(require("./model"));
|
|
11
|
+
const filesystem_routes_1 = __importDefault(require("./filesystem-routes"));
|
|
12
|
+
var buildHtml_1 = require("./main/buildHtml");
|
|
13
|
+
Object.defineProperty(exports, "buildHtml", { enumerable: true, get: function () { return buildHtml_1.buildHtml; } });
|
|
14
|
+
var middlewares_1 = require("./middlewares");
|
|
15
|
+
Object.defineProperty(exports, "getMiddlewares", { enumerable: true, get: function () { return middlewares_1.getMiddlewares; } });
|
|
16
|
+
Object.defineProperty(exports, "getMiddlewaresBeforeDevMiddlewares", { enumerable: true, get: function () { return middlewares_1.getMiddlewaresBeforeDevMiddlewares; } });
|
|
17
|
+
var main_1 = require("./main");
|
|
18
|
+
Object.defineProperty(exports, "getMainPlugin", { enumerable: true, get: function () { return main_1.getPlugin; } });
|
|
19
|
+
exports.featurePlugins = [
|
|
20
|
+
on_demand_compile_page_1.default,
|
|
21
|
+
filesystem_routes_1.default,
|
|
22
|
+
html_render_1.default,
|
|
23
|
+
custom_server_1.default,
|
|
24
|
+
model_1.default
|
|
25
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IPlatformContent, IPluginContext, ServerPluginInstance } from '@shuvi/service';
|
|
2
|
+
export declare const buildHtml: ({ context, serverPlugins, getMiddlewares, pathname, filename }: {
|
|
3
|
+
context: IPluginContext;
|
|
4
|
+
serverPlugins: ServerPluginInstance[];
|
|
5
|
+
getMiddlewares: IPlatformContent['getMiddlewares'];
|
|
6
|
+
pathname: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
}) => Promise<void>;
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.buildHtml = void 0;
|
|
36
|
+
const events_1 = require("events");
|
|
37
|
+
const fse = __importStar(require("fs-extra"));
|
|
38
|
+
const node_mocks_http_1 = require("node-mocks-http");
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const service_1 = require("@shuvi/service");
|
|
41
|
+
const buildHtml = ({ context, serverPlugins, getMiddlewares, pathname, filename }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
return new Promise(resolve => {
|
|
43
|
+
const request = (0, node_mocks_http_1.createRequest)({
|
|
44
|
+
url: pathname
|
|
45
|
+
});
|
|
46
|
+
const response = (0, node_mocks_http_1.createResponse)({
|
|
47
|
+
eventEmitter: events_1.EventEmitter
|
|
48
|
+
});
|
|
49
|
+
response.on('end', () => {
|
|
50
|
+
const html = response._getBuffer();
|
|
51
|
+
fse.writeFileSync(path.resolve(context.paths.buildDir, service_1.BUILD_DEFAULT_DIR, filename), html);
|
|
52
|
+
resolve();
|
|
53
|
+
});
|
|
54
|
+
(0, service_1.createShuviServer)({
|
|
55
|
+
context,
|
|
56
|
+
serverPlugins,
|
|
57
|
+
getMiddlewares
|
|
58
|
+
}).then(server => {
|
|
59
|
+
const requestHandler = server.getRequestHandler();
|
|
60
|
+
requestHandler(request, response);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
exports.buildHtml = buildHtml;
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const path = __importStar(require("path"));
|
|
27
|
+
const fse = __importStar(require("fs-extra"));
|
|
28
|
+
const service_1 = require("@shuvi/service");
|
|
29
|
+
const file_utils_1 = require("@shuvi/service/lib/project/file-utils");
|
|
30
|
+
const generateResources = (context) => {
|
|
31
|
+
const { resolveUserFile } = context;
|
|
32
|
+
const { buildDir } = context.paths;
|
|
33
|
+
const clientManifestRequest = (0, file_utils_1.urlToRequest)(path.join(buildDir, service_1.BUILD_DEFAULT_DIR, service_1.CLIENT_BUILD_MANIFEST_PATH));
|
|
34
|
+
const serverManifestRequest = (0, file_utils_1.urlToRequest)(path.join(buildDir, service_1.BUILD_SERVER_DIR, service_1.SERVER_BUILD_MANIFEST_PATH));
|
|
35
|
+
const serverModuleDir = path.join(buildDir, service_1.BUILD_SERVER_DIR);
|
|
36
|
+
const result = [];
|
|
37
|
+
result.push(['clientManifest', clientManifestRequest]);
|
|
38
|
+
result.push(['serverManifest', serverManifestRequest]);
|
|
39
|
+
result.push([
|
|
40
|
+
`server = function() {
|
|
41
|
+
const path = require('path');
|
|
42
|
+
const relativeModulePath = require('${serverManifestRequest}')['bundles']['${service_1.BUILD_SERVER_FILE_SERVER}'];
|
|
43
|
+
const modulePath = require.resolve(path.join("${serverModuleDir}", relativeModulePath));
|
|
44
|
+
return require(modulePath)
|
|
45
|
+
}`,
|
|
46
|
+
undefined
|
|
47
|
+
]);
|
|
48
|
+
const customDoc = resolveUserFile('document.ejs');
|
|
49
|
+
let documentPath = require.resolve('@shuvi/platform-shared/template/document.ejs');
|
|
50
|
+
if (fse.existsSync(customDoc)) {
|
|
51
|
+
documentPath = customDoc;
|
|
52
|
+
}
|
|
53
|
+
result.push([`documentPath = "${documentPath}"`, undefined]);
|
|
54
|
+
return result;
|
|
55
|
+
};
|
|
56
|
+
exports.default = generateResources;
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getPlugin = void 0;
|
|
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");
|
|
19
|
+
const generateResource_1 = __importDefault(require("./generateResource"));
|
|
20
|
+
const paths_1 = require("../../paths");
|
|
21
|
+
const buildHtml_1 = require("./buildHtml");
|
|
22
|
+
const middlewares_1 = require("../middlewares");
|
|
23
|
+
function getServerEntry() {
|
|
24
|
+
return {
|
|
25
|
+
[service_1.BUILD_SERVER_FILE_SERVER]: [(0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/server')]
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** This main plugin uses `platformContext` so that it is set to a plugin getter */
|
|
29
|
+
const getPlugin = (platformContext) => {
|
|
30
|
+
const core = (0, service_1.createPlugin)({
|
|
31
|
+
addExtraTarget: ({ createConfig }, context) => {
|
|
32
|
+
const serverWebpackHelpers = (0, config_1.webpackHelpers)();
|
|
33
|
+
const serverChain = createConfig({
|
|
34
|
+
name: constants_1.BUNDLER_TARGET_SERVER,
|
|
35
|
+
node: true,
|
|
36
|
+
entry: getServerEntry(),
|
|
37
|
+
outputDir: service_1.BUILD_SERVER_DIR,
|
|
38
|
+
webpackHelpers: serverWebpackHelpers
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
name: constants_1.BUNDLER_TARGET_SERVER,
|
|
42
|
+
chain: serverChain
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
configWebpack: chain => {
|
|
46
|
+
chain.merge({
|
|
47
|
+
entry: {
|
|
48
|
+
[service_1.BUILD_CLIENT_RUNTIME_POLYFILL]: ['@shuvi/app/core/polyfill'],
|
|
49
|
+
[service_1.BUILD_CLIENT_RUNTIME_MAIN]: [
|
|
50
|
+
(0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/client')
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return chain;
|
|
55
|
+
},
|
|
56
|
+
addRuntimeService: () => [
|
|
57
|
+
{
|
|
58
|
+
source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/shuvi-runtime-index'),
|
|
59
|
+
exported: '*'
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/shuvi-runtime-server'),
|
|
63
|
+
filepath: 'server.ts',
|
|
64
|
+
exported: '*'
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
addResource: context => (0, generateResource_1.default)(context),
|
|
68
|
+
afterBuild: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
69
|
+
yield (0, buildHtml_1.buildHtml)({
|
|
70
|
+
context,
|
|
71
|
+
serverPlugins: platformContext.serverPlugins,
|
|
72
|
+
getMiddlewares: middlewares_1.getMiddlewares,
|
|
73
|
+
pathname: '/',
|
|
74
|
+
filename: 'index.html'
|
|
75
|
+
});
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
core
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
exports.getPlugin = getPlugin;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { IServerPluginContext, IServerMiddleware } from '@shuvi/service';
|
|
2
|
+
import { DevMiddleware } from '@shuvi/service/lib/server/middlewares/dev/devMiddleware';
|
|
3
|
+
export declare const getMiddlewares: (context: IServerPluginContext) => IServerMiddleware[];
|
|
4
|
+
export declare const getMiddlewaresBeforeDevMiddlewares: (devMiddleware: DevMiddleware, context: IServerPluginContext) => IServerMiddleware[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMiddlewaresBeforeDevMiddlewares = exports.getMiddlewares = void 0;
|
|
4
|
+
const on_demand_compile_page_1 = require("./on-demand-compile-page");
|
|
5
|
+
const filesystem_routes_1 = require("./filesystem-routes");
|
|
6
|
+
const html_render_1 = require("./html-render");
|
|
7
|
+
const getMiddlewares = (context) => {
|
|
8
|
+
return [
|
|
9
|
+
(0, filesystem_routes_1.getMiddlewareMiddleware)(context),
|
|
10
|
+
(0, filesystem_routes_1.getApiMiddleware)(context),
|
|
11
|
+
(0, html_render_1.getPageMiddleware)(context)
|
|
12
|
+
].filter(Boolean);
|
|
13
|
+
};
|
|
14
|
+
exports.getMiddlewares = getMiddlewares;
|
|
15
|
+
const getMiddlewaresBeforeDevMiddlewares = (devMiddleware, context) => {
|
|
16
|
+
const onDemandRouteManager = new on_demand_compile_page_1.OnDemandRouteManager(context);
|
|
17
|
+
onDemandRouteManager.devMiddleware = devMiddleware;
|
|
18
|
+
return [
|
|
19
|
+
onDemandRouteManager.getServerMiddleware(),
|
|
20
|
+
onDemandRouteManager.ensureRoutesMiddleware() // check page request
|
|
21
|
+
];
|
|
22
|
+
};
|
|
23
|
+
exports.getMiddlewaresBeforeDevMiddlewares = getMiddlewaresBeforeDevMiddlewares;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
core: import("@shuvi/hook").IPluginInstance<{
|
|
3
|
+
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
4
|
+
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
5
|
+
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
6
|
+
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
+
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
8
|
+
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
9
|
+
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
10
|
+
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
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").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
13
|
+
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
14
|
+
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
15
|
+
runtime: {
|
|
16
|
+
plugin: string;
|
|
17
|
+
};
|
|
18
|
+
server: import("@shuvi/service").ServerPluginInstance;
|
|
19
|
+
types: string;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|