@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
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getPageMiddleware = void 0;
|
|
13
13
|
const utils_1 = require("@shuvi/service/lib/server/utils");
|
|
14
|
-
const renderToHTML_1 = require("./renderToHTML");
|
|
15
14
|
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
15
|
+
const renderToHTML_1 = require("./renderToHTML");
|
|
16
16
|
function createPageHandler(serverPluginContext) {
|
|
17
17
|
return function (req, res) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -40,17 +40,22 @@ function createPageHandler(serverPluginContext) {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
function getPageMiddleware(api) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const defaultPageHandler = createPageHandler(api);
|
|
45
|
+
let pageHandler;
|
|
46
|
+
return function (req, res, next) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
if (!pageHandler) {
|
|
49
|
+
pageHandler = yield api.serverPluginRunner.handlePageRequest(defaultPageHandler);
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
yield pageHandler(req, res);
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
next(error);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
});
|
|
55
60
|
}
|
|
56
61
|
exports.getPageMiddleware = getPageMiddleware;
|
|
@@ -14,10 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.getPageMiddleware = void 0;
|
|
18
18
|
var getPageMiddleware_1 = require("./getPageMiddleware");
|
|
19
19
|
Object.defineProperty(exports, "getPageMiddleware", { enumerable: true, get: function () { return getPageMiddleware_1.getPageMiddleware; } });
|
|
20
|
-
var renderToHTML_1 = require("./renderToHTML");
|
|
21
|
-
Object.defineProperty(exports, "renderToHTML", { enumerable: true, get: function () { return renderToHTML_1.renderToHTML; } });
|
|
22
20
|
__exportStar(require("./renderer"), exports);
|
|
23
|
-
__exportStar(require("./pageLoader"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ShuviRequest, IServerPluginContext } from '@shuvi/service';
|
|
2
2
|
import { Response } from '@shuvi/platform-shared/shared';
|
|
3
3
|
export declare function renderToHTML({ req, serverPluginContext }: {
|
|
4
|
-
req:
|
|
4
|
+
req: ShuviRequest;
|
|
5
5
|
serverPluginContext: IServerPluginContext;
|
|
6
6
|
}): Promise<Response>;
|
|
@@ -8,69 +8,29 @@ 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.renderToHTML = void 0;
|
|
13
|
-
const resources_1 = require("@shuvi/service/lib/resources");
|
|
14
|
-
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
16
|
+
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
15
17
|
const renderer_1 = require("./renderer");
|
|
16
|
-
const htmlTag_1 = require("./renderer/htmlTag");
|
|
17
|
-
function addEssentialTagsIfMissing(document) {
|
|
18
|
-
let hasMetaCharset = false;
|
|
19
|
-
let hasMetaViewport = false;
|
|
20
|
-
for (const { tagName, attrs } of document.headTags) {
|
|
21
|
-
if (hasMetaCharset && hasMetaViewport) {
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
if (tagName === 'meta') {
|
|
25
|
-
if (attrs.charset) {
|
|
26
|
-
hasMetaCharset = true;
|
|
27
|
-
}
|
|
28
|
-
else if (attrs.name === 'viewport') {
|
|
29
|
-
hasMetaViewport = true;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (!hasMetaCharset) {
|
|
34
|
-
document.headTags.unshift((0, htmlTag_1.tag)('meta', {
|
|
35
|
-
charset: 'utf-8'
|
|
36
|
-
}));
|
|
37
|
-
}
|
|
38
|
-
if (!hasMetaViewport) {
|
|
39
|
-
document.headTags.unshift((0, htmlTag_1.tag)('meta', {
|
|
40
|
-
name: 'viewport',
|
|
41
|
-
content: 'width=device-width,minimum-scale=1,initial-scale=1'
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
return document;
|
|
45
|
-
}
|
|
46
18
|
function renderToHTML({ req, serverPluginContext }) {
|
|
47
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
20
|
let result;
|
|
49
21
|
const renderer = new renderer_1.Renderer({ serverPluginContext });
|
|
50
|
-
const { application } = resources_1.server;
|
|
22
|
+
const { application } = resources_1.default.server;
|
|
51
23
|
const app = application.createApp({
|
|
52
24
|
req,
|
|
53
25
|
ssr: serverPluginContext.config.ssr
|
|
54
26
|
});
|
|
55
27
|
try {
|
|
56
28
|
yield app.init();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
app:
|
|
60
|
-
|
|
29
|
+
result = yield renderer.renderView({
|
|
30
|
+
req,
|
|
31
|
+
app: app.getPublicAPI(),
|
|
32
|
+
ssr: serverPluginContext.config.ssr
|
|
61
33
|
});
|
|
62
|
-
if ((0, shared_1.isResponse)(doc)) {
|
|
63
|
-
result = doc;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
addEssentialTagsIfMissing(doc);
|
|
67
|
-
yield serverPluginContext.serverPluginRunner.modifyHtml(doc, app.context);
|
|
68
|
-
const htmlStr = renderer.renderDocumentToString(doc);
|
|
69
|
-
const appError = app.error.getError;
|
|
70
|
-
result = (0, shared_1.text)(htmlStr, {
|
|
71
|
-
status: appError && typeof appError.code !== 'undefined' ? appError.code : 200
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
34
|
}
|
|
75
35
|
finally {
|
|
76
36
|
yield app.dispose();
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { IAppData
|
|
2
|
-
import { IServerPluginContext } from '@shuvi/service';
|
|
3
|
-
import {
|
|
4
|
-
import { IRendererConstructorOptions, IRenderDocumentOptions } from './types';
|
|
1
|
+
import { IAppData } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { ShuviRequest, IServerPluginContext } from '@shuvi/service';
|
|
3
|
+
import { IHtmlTag, Application, IRendererConstructorOptions, IRenderViewOptions, IRenderDocumentResult } from './types';
|
|
5
4
|
export declare type AppData = Omit<IAppData, 'filesByRoutId' | 'publicPath'>;
|
|
6
5
|
export declare abstract class BaseRenderer {
|
|
7
6
|
protected _serverPluginContext: IServerPluginContext;
|
|
8
|
-
protected _app?:
|
|
7
|
+
protected _app?: Application;
|
|
9
8
|
constructor({ serverPluginContext }: IRendererConstructorOptions);
|
|
10
|
-
abstract renderDocument({ app, req }:
|
|
11
|
-
protected _getMainAssetTags(): {
|
|
9
|
+
abstract renderDocument({ app, req }: IRenderViewOptions): IRenderDocumentResult;
|
|
10
|
+
protected _getMainAssetTags(req: ShuviRequest): {
|
|
12
11
|
styles: IHtmlTag<any>[];
|
|
13
12
|
scripts: IHtmlTag<any>[];
|
|
14
13
|
};
|
|
15
14
|
protected _getAppContainerTag(html?: string): IHtmlTag<'div'>;
|
|
16
|
-
protected _getInlineAppData(app:
|
|
15
|
+
protected _getInlineAppData(app: Application, appData: AppData): IHtmlTag;
|
|
17
16
|
}
|
|
@@ -5,33 +5,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BaseRenderer = void 0;
|
|
7
7
|
const htmlescape_1 = require("@shuvi/utils/lib/htmlescape");
|
|
8
|
-
const service_1 = require("@shuvi/service");
|
|
9
8
|
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
10
|
-
const resources_1 = require("@shuvi/service/lib/resources");
|
|
9
|
+
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
10
|
+
const shared_1 = require("../../../../../shared");
|
|
11
11
|
const generateFilesByRoutId_1 = __importDefault(require("../generateFilesByRoutId"));
|
|
12
12
|
const htmlTag_1 = require("./htmlTag");
|
|
13
|
+
function getPolyfillScripts(req, manifest) {
|
|
14
|
+
if (!manifest.polyfillFiles) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
return manifest.polyfillFiles
|
|
18
|
+
.filter(polyfill => polyfill.endsWith('.js'))
|
|
19
|
+
.map(polyfill => (0, htmlTag_1.tag)('script', {
|
|
20
|
+
src: req.getAssetUrl(polyfill),
|
|
21
|
+
nomodule: true
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
13
24
|
class BaseRenderer {
|
|
14
25
|
constructor({ serverPluginContext }) {
|
|
15
26
|
this._serverPluginContext = serverPluginContext;
|
|
16
27
|
}
|
|
17
|
-
_getMainAssetTags() {
|
|
28
|
+
_getMainAssetTags(req) {
|
|
18
29
|
const styles = [];
|
|
19
30
|
const scripts = [];
|
|
20
|
-
const entrypoints = resources_1.clientManifest.entries[
|
|
21
|
-
|
|
22
|
-
scripts.push((0, htmlTag_1.tag)('script', {
|
|
23
|
-
src: this._serverPluginContext.getAssetPublicUrl(polyfill)
|
|
24
|
-
}));
|
|
31
|
+
const entrypoints = resources_1.default.clientManifest.entries[shared_1.BUILD_CLIENT_RUNTIME_MAIN];
|
|
32
|
+
getPolyfillScripts(req, resources_1.default.clientManifest).forEach(item => scripts.push(item));
|
|
25
33
|
entrypoints.js.forEach((asset) => {
|
|
26
34
|
scripts.push((0, htmlTag_1.tag)('script', {
|
|
27
|
-
src:
|
|
35
|
+
src: req.getAssetUrl(asset)
|
|
28
36
|
}));
|
|
29
37
|
});
|
|
30
38
|
if (entrypoints.css) {
|
|
31
39
|
entrypoints.css.forEach((asset) => {
|
|
32
40
|
styles.push((0, htmlTag_1.tag)('link', {
|
|
33
41
|
rel: 'stylesheet',
|
|
34
|
-
href:
|
|
42
|
+
href: req.getAssetUrl(asset)
|
|
35
43
|
}));
|
|
36
44
|
});
|
|
37
45
|
}
|
|
@@ -60,7 +68,7 @@ class BaseRenderer {
|
|
|
60
68
|
}
|
|
61
69
|
_getInlineAppData(app, appData) {
|
|
62
70
|
const routes = app.router.routes || [];
|
|
63
|
-
const data = JSON.stringify(Object.assign(Object.assign({}, appData), { filesByRoutId: (0, generateFilesByRoutId_1.default)(resources_1.clientManifest, routes), publicPath: this._serverPluginContext.
|
|
71
|
+
const data = JSON.stringify(Object.assign(Object.assign({}, appData), { filesByRoutId: (0, generateFilesByRoutId_1.default)(resources_1.default.clientManifest, routes), publicPath: this._serverPluginContext.assetPublicPath }));
|
|
64
72
|
return (0, htmlTag_1.tag)('script', {
|
|
65
73
|
id: constants_1.CLIENT_APPDATA_ID,
|
|
66
74
|
type: 'application/json'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Response } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { IRendererConstructorOptions, IRenderViewOptions } from './types';
|
|
3
3
|
export * from './types';
|
|
4
4
|
export interface ITemplateData {
|
|
5
5
|
[x: string]: any;
|
|
@@ -10,6 +10,7 @@ export declare class Renderer {
|
|
|
10
10
|
private _ssrRenderer;
|
|
11
11
|
private _spaRenderer;
|
|
12
12
|
constructor(options: IRendererConstructorOptions);
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
renderView(options: IRenderViewOptions): Promise<Response>;
|
|
14
|
+
private _renderDocument;
|
|
15
|
+
private _renderDocumentToString;
|
|
15
16
|
}
|
|
@@ -13,28 +13,97 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
19
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
20
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
21
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
22
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
16
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
29
|
exports.Renderer = void 0;
|
|
18
|
-
const resources_1 = require("@shuvi/service/lib/resources");
|
|
30
|
+
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
31
|
+
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
19
32
|
const htmlTag_1 = require("./htmlTag");
|
|
20
33
|
const viewTemplate_1 = require("../viewTemplate");
|
|
21
34
|
const spa_1 = require("./spa");
|
|
22
35
|
const ssr_1 = require("./ssr");
|
|
36
|
+
const htmlTag_2 = require("./htmlTag");
|
|
23
37
|
__exportStar(require("./types"), exports);
|
|
38
|
+
function addEssentialTagsIfMissing(document) {
|
|
39
|
+
let hasMetaCharset = false;
|
|
40
|
+
let hasMetaViewport = false;
|
|
41
|
+
for (const { tagName, attrs } of document.headTags) {
|
|
42
|
+
if (hasMetaCharset && hasMetaViewport) {
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
if (tagName === 'meta') {
|
|
46
|
+
if (attrs.charset) {
|
|
47
|
+
hasMetaCharset = true;
|
|
48
|
+
}
|
|
49
|
+
else if (attrs.name === 'viewport') {
|
|
50
|
+
hasMetaViewport = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!hasMetaCharset) {
|
|
55
|
+
document.headTags.unshift((0, htmlTag_2.tag)('meta', {
|
|
56
|
+
charset: 'utf-8'
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
if (!hasMetaViewport) {
|
|
60
|
+
document.headTags.unshift((0, htmlTag_2.tag)('meta', {
|
|
61
|
+
name: 'viewport',
|
|
62
|
+
content: 'width=device-width,minimum-scale=1,initial-scale=1'
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
return document;
|
|
66
|
+
}
|
|
24
67
|
class Renderer {
|
|
25
68
|
constructor(options) {
|
|
26
69
|
this._serverPluginContext = options.serverPluginContext;
|
|
27
|
-
this._documentTemplate = (0, viewTemplate_1.parseTemplateFile)(resources_1.documentPath);
|
|
70
|
+
this._documentTemplate = (0, viewTemplate_1.parseTemplateFile)(resources_1.default.documentPath);
|
|
28
71
|
this._ssrRenderer = new ssr_1.SsrRenderer(options);
|
|
29
72
|
this._spaRenderer = new spa_1.SpaRenderer(options);
|
|
30
73
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
74
|
+
renderView(options) {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
let result;
|
|
78
|
+
const { app, req } = options;
|
|
79
|
+
const doc = yield this._renderDocument(options);
|
|
80
|
+
if ((0, shared_1.isResponse)(doc)) {
|
|
81
|
+
result = doc;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
addEssentialTagsIfMissing(doc);
|
|
85
|
+
yield this._serverPluginContext.serverPluginRunner.modifyHtml(doc, {
|
|
86
|
+
req,
|
|
87
|
+
appContext: app.context
|
|
88
|
+
});
|
|
89
|
+
const htmlStr = this._renderDocumentToString(doc);
|
|
90
|
+
result = (0, shared_1.text)(htmlStr, {
|
|
91
|
+
status: (_b = (_a = app.error) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : 200
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
_renderDocument(options) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
// todo: fallback to spa
|
|
100
|
+
if (options.ssr) {
|
|
101
|
+
return yield this._ssrRenderer.renderDocument(options);
|
|
102
|
+
}
|
|
103
|
+
return yield this._spaRenderer.renderDocument(options);
|
|
104
|
+
});
|
|
36
105
|
}
|
|
37
|
-
|
|
106
|
+
_renderDocumentToString(document, templateData = {}) {
|
|
38
107
|
const htmlAttrs = (0, htmlTag_1.stringifyAttrs)(document.htmlAttrs);
|
|
39
108
|
const head = document.headTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
|
|
40
109
|
const main = document.mainTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseRenderer } from './base';
|
|
2
|
-
import {
|
|
2
|
+
import { IRenderViewOptions, IHtmlDocument } from './types';
|
|
3
3
|
export declare class SpaRenderer extends BaseRenderer {
|
|
4
|
-
renderDocument({ app }:
|
|
4
|
+
renderDocument({ req, app }: IRenderViewOptions): IHtmlDocument;
|
|
5
5
|
}
|
|
@@ -3,13 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SpaRenderer = void 0;
|
|
4
4
|
const base_1 = require("./base");
|
|
5
5
|
class SpaRenderer extends base_1.BaseRenderer {
|
|
6
|
-
renderDocument({ app }) {
|
|
7
|
-
const assets = this._getMainAssetTags();
|
|
8
|
-
const serverPluginContext = this._serverPluginContext;
|
|
6
|
+
renderDocument({ req, app }) {
|
|
7
|
+
const assets = this._getMainAssetTags(req);
|
|
9
8
|
const appData = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
loadersData: {}
|
|
9
|
+
ssr: false,
|
|
10
|
+
pageData: {}
|
|
13
11
|
};
|
|
14
12
|
const document = {
|
|
15
13
|
htmlAttrs: {},
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseRenderer } from './base';
|
|
2
|
-
import { IHtmlDocument,
|
|
2
|
+
import { IHtmlDocument, IRenderViewOptions } from './types';
|
|
3
3
|
export declare class SsrRenderer extends BaseRenderer {
|
|
4
|
-
renderDocument({ app, req }:
|
|
4
|
+
renderDocument({ app, req }: IRenderViewOptions): Promise<import("@shuvi/platform-shared/shared").Response | IHtmlDocument>;
|
|
5
5
|
}
|
|
@@ -8,40 +8,39 @@ 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.SsrRenderer = void 0;
|
|
13
16
|
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
14
17
|
const shuvi_singleton_runtimeConfig_1 = require("@shuvi/platform-shared/shared/shuvi-singleton-runtimeConfig");
|
|
15
|
-
const
|
|
16
|
-
const resources_1 = require("@shuvi/service/lib/resources");
|
|
18
|
+
const resources_1 = __importDefault(require("@shuvi/service/lib/resources"));
|
|
17
19
|
const base_1 = require("./base");
|
|
18
|
-
const htmlTag_1 = require("./htmlTag");
|
|
19
20
|
class SsrRenderer extends base_1.BaseRenderer {
|
|
20
21
|
renderDocument({ app, req }) {
|
|
21
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const { router, context } = app;
|
|
23
|
+
const { store, router, context } = app;
|
|
23
24
|
const serverPluginContext = this._serverPluginContext;
|
|
24
|
-
const { view } = resources_1.server;
|
|
25
|
-
const { getAssetPublicUrl } = serverPluginContext;
|
|
25
|
+
const { view } = resources_1.default.server;
|
|
26
26
|
if (!router) {
|
|
27
27
|
throw new Error('router is null');
|
|
28
28
|
}
|
|
29
29
|
const result = yield view.renderApp({
|
|
30
30
|
app,
|
|
31
31
|
req,
|
|
32
|
-
manifest: resources_1.clientManifest
|
|
33
|
-
getAssetPublicUrl
|
|
32
|
+
manifest: resources_1.default.clientManifest
|
|
34
33
|
});
|
|
35
34
|
if ((0, shared_1.isResponse)(result)) {
|
|
36
35
|
return result;
|
|
37
36
|
}
|
|
38
|
-
const mainAssetsTags = this._getMainAssetTags();
|
|
37
|
+
const mainAssetsTags = this._getMainAssetTags(req);
|
|
39
38
|
const pageDataList = yield serverPluginContext.serverPluginRunner.getPageData(context);
|
|
40
39
|
const pageData = pageDataList.reduce((acc, data) => {
|
|
41
40
|
Object.assign(acc, data);
|
|
42
41
|
return acc;
|
|
43
42
|
}, {});
|
|
44
|
-
const appData = Object.assign(Object.assign({}, result.appData), {
|
|
43
|
+
const appData = Object.assign(Object.assign({}, result.appData), { ssr: true, appState: store.getState(), pageData });
|
|
45
44
|
appData.runtimeConfig = (0, shuvi_singleton_runtimeConfig_1.getPublicRuntimeConfig)() || {};
|
|
46
45
|
const document = {
|
|
47
46
|
htmlAttrs: Object.assign({}, result.htmlAttrs),
|
|
@@ -57,7 +56,6 @@ class SsrRenderer extends base_1.BaseRenderer {
|
|
|
57
56
|
...(result.mainEndTags || [])
|
|
58
57
|
],
|
|
59
58
|
scriptTags: [
|
|
60
|
-
(0, htmlTag_1.tag)('script', {}, `${constants_1.IDENTITY_RUNTIME_PUBLICPATH} = "${serverPluginContext.assetPublicPath}"`),
|
|
61
59
|
...(result.scriptBeginTags || []),
|
|
62
60
|
...mainAssetsTags.scripts,
|
|
63
61
|
...(result.scriptEndTags || [])
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export { IHtmlAttrs, IHtmlTag,
|
|
1
|
+
import { Response } from '@shuvi/platform-shared/shared';
|
|
2
|
+
import { ShuviRequest, IServerPluginContext } from '@shuvi/service';
|
|
3
|
+
import { IHtmlAttrs, IHtmlTag, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer, IRenderAppServerResult, Application } from '../../../../../shared';
|
|
4
|
+
export { IHtmlAttrs, IHtmlTag, Application };
|
|
5
5
|
export interface IRendererConstructorOptions {
|
|
6
6
|
serverPluginContext: IServerPluginContext;
|
|
7
7
|
}
|
|
8
|
-
export declare type
|
|
9
|
-
app:
|
|
10
|
-
req:
|
|
8
|
+
export declare type IRenderViewOptions = {
|
|
9
|
+
app: Application;
|
|
10
|
+
req: ShuviRequest;
|
|
11
|
+
ssr: boolean;
|
|
11
12
|
};
|
|
13
|
+
export declare type IRenderDocumentResult = Promise<IHtmlDocument | Response> | IHtmlDocument | Response;
|
|
12
14
|
export interface IHtmlDocument {
|
|
13
15
|
htmlAttrs: IHtmlAttrs;
|
|
14
16
|
headTags: IHtmlTag<'meta' | 'link' | 'style' | 'script' | 'noscript' | 'title'>[];
|
|
15
17
|
mainTags: IHtmlTag[];
|
|
16
18
|
scriptTags: IHtmlTag<'script'>[];
|
|
17
19
|
}
|
|
18
|
-
export interface IRenderOptions extends
|
|
20
|
+
export interface IRenderOptions extends IRenderViewOptions {
|
|
19
21
|
}
|
|
20
22
|
export { IRenderAppServerResult, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Compiler, Compilation, Plugin } from '@shuvi/toolpack/lib/webpack';
|
|
2
|
+
interface Options {
|
|
3
|
+
filename: string;
|
|
4
|
+
modules: boolean;
|
|
5
|
+
chunkRequest: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default class BuildManifestPlugin implements Plugin {
|
|
8
|
+
private _options;
|
|
9
|
+
private _manifest;
|
|
10
|
+
constructor(options?: Partial<Options>);
|
|
11
|
+
createAssets(compiler: Compiler, compilation: Compilation): {
|
|
12
|
+
entries: {};
|
|
13
|
+
bundles: {};
|
|
14
|
+
chunkRequest: {};
|
|
15
|
+
loadble: {};
|
|
16
|
+
};
|
|
17
|
+
apply(compiler: Compiler): void;
|
|
18
|
+
private _collectEntries;
|
|
19
|
+
private _collect;
|
|
20
|
+
private _collectChunk;
|
|
21
|
+
private _collectChunkModule;
|
|
22
|
+
private _pushEntries;
|
|
23
|
+
private _pushBundle;
|
|
24
|
+
private _pushChunkRequest;
|
|
25
|
+
private _pushLoadableModules;
|
|
26
|
+
}
|
|
27
|
+
export {};
|