@shuvi/platform-web 1.0.0-rc.2 → 1.0.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/shared/appTypes.d.ts +2 -2
- package/esm/shared/renderTypes.d.ts +2 -2
- package/esm/shuvi-app/app/client.d.ts +2 -0
- package/esm/shuvi-app/app/client.js +12 -11
- package/esm/shuvi-app/app/server.js +4 -5
- package/esm/shuvi-app/dev/eventsource.d.ts +1 -0
- package/esm/shuvi-app/dev/eventsource.js +60 -0
- package/esm/shuvi-app/dev/hotDevClient.d.ts +33 -0
- package/esm/shuvi-app/dev/hotDevClient.js +348 -0
- package/esm/shuvi-app/dev/index.d.ts +3 -0
- package/esm/shuvi-app/dev/index.js +27 -0
- package/esm/shuvi-app/dev/websocket.d.ts +17 -0
- package/esm/shuvi-app/dev/websocket.js +61 -0
- package/esm/shuvi-app/entry/client/app.d.ts +2 -1
- package/esm/shuvi-app/entry/client/app.js +2 -2
- package/esm/shuvi-app/entry/client/run.dev.js +4 -4
- package/esm/shuvi-app/entry/server/index.d.ts +5 -4
- package/esm/shuvi-app/entry/server/index.js +5 -4
- package/esm/shuvi-app/react/AppContainer.d.ts +2 -3
- package/esm/shuvi-app/react/AppContainer.jsx +3 -4
- package/esm/shuvi-app/react/getRoutes.d.ts +2 -2
- package/esm/shuvi-app/react/getRoutes.js +6 -7
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.d.ts +2 -2
- package/esm/shuvi-app/react/redox-react/RedoxWrapper.jsx +3 -3
- package/esm/shuvi-app/react/redox-react/runtime.d.ts +7 -1
- package/esm/shuvi-app/react/redox-react/runtime.js +3 -1
- package/esm/shuvi-app/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 +11 -20
- package/esm/shuvi-app/react/view/ReactView.client.jsx +4 -4
- package/esm/shuvi-app/react/view/ReactView.server.jsx +4 -10
- package/esm/shuvi-app/shuvi-runtime-index.js +1 -1
- package/lib/node/features/filesystem-routes/index.d.ts +1 -1
- package/lib/node/features/filesystem-routes/index.js +17 -7
- package/lib/node/features/filesystem-routes/page/routes.d.ts +2 -2
- package/lib/node/features/filesystem-routes/page/routes.js +29 -11
- package/lib/node/features/html-render/index.d.ts +3 -18
- package/lib/node/features/html-render/index.js +87 -16
- package/lib/node/features/{main → html-render/lib}/buildHtml.d.ts +0 -0
- package/lib/node/features/{main → html-render/lib}/buildHtml.js +0 -0
- package/lib/node/features/html-render/lib/generateFilesByRoutId.d.ts +2 -2
- package/lib/node/features/html-render/lib/generateFilesByRoutId.js +3 -3
- package/lib/node/features/{main → html-render/lib}/generateResource.d.ts +0 -0
- package/lib/node/features/{main → html-render/lib}/generateResource.js +0 -0
- package/lib/node/features/html-render/lib/index.d.ts +0 -1
- package/lib/node/features/html-render/lib/index.js +1 -3
- package/lib/node/features/html-render/lib/renderToHTML.js +4 -47
- package/lib/node/features/html-render/lib/renderer/base.d.ts +4 -4
- package/lib/node/features/html-render/lib/renderer/index.d.ts +5 -4
- package/lib/node/features/html-render/lib/renderer/index.js +69 -6
- package/lib/node/features/html-render/lib/renderer/spa.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderer/spa.js +2 -4
- package/lib/node/features/html-render/lib/renderer/ssr.d.ts +2 -2
- package/lib/node/features/html-render/lib/renderer/ssr.js +2 -2
- package/lib/node/features/html-render/lib/renderer/types.d.ts +6 -4
- package/lib/node/features/index.d.ts +3 -31
- package/lib/node/features/index.js +6 -7
- package/lib/node/features/model/index.d.ts +1 -1
- package/lib/node/features/model/runtime.d.ts +0 -5
- package/lib/node/features/model/runtime.js +11 -17
- package/lib/node/features/model/server.js +2 -3
- package/lib/node/features/model/shuvi-app.d.ts +1 -1
- package/lib/node/features/on-demand-compile-page/index.d.ts +15 -13
- package/lib/node/features/on-demand-compile-page/index.js +4 -1
- package/lib/node/features/on-demand-compile-page/onDemandRouteManager.js +2 -4
- package/lib/node/index.js +1 -3
- package/lib/node/shuvi-runtime-server.d.ts +18 -0
- package/lib/node/shuvi-runtime-server.js +2 -0
- package/lib/node/shuvi-type-extensions-node.d.ts +2 -6
- package/lib/node/targets/react/bundler/index.d.ts +1 -1
- package/lib/node/targets/react/bundler/index.js +5 -0
- package/lib/node/targets/react/index.d.ts +2 -2
- package/lib/node/targets/react/redox-react/index.d.ts +1 -1
- package/lib/shared/appTypes.d.ts +2 -2
- package/lib/shared/renderTypes.d.ts +2 -2
- package/package.json +17 -12
- package/shuvi-env.d.ts +10 -0
- package/shuvi-image.d.ts +54 -0
- package/shuvi-type-extensions-node.js +1 -0
- package/shuvi-type-extensions-runtime.d.ts +2 -2
- package/esm/shuvi-app/dev/webpackHotDevClient.d.ts +0 -5
- package/esm/shuvi-app/dev/webpackHotDevClient.js +0 -34
- package/esm/shuvi-app/shuvi-runtime-server.d.ts +0 -6
- package/esm/shuvi-app/shuvi-runtime-server.js +0 -1
- package/lib/node/features/main/index.d.ts +0 -3
- package/lib/node/features/main/index.js +0 -82
|
@@ -1,28 +1,99 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getPageMiddleware = void 0;
|
|
15
|
+
exports.getPlugin = exports.getPageMiddleware = void 0;
|
|
7
16
|
const service_1 = require("@shuvi/service");
|
|
17
|
+
const constants_1 = require("@shuvi/shared/lib/constants");
|
|
18
|
+
const config_1 = require("@shuvi/toolpack/lib/webpack/config");
|
|
8
19
|
const paths_1 = require("../../paths");
|
|
20
|
+
const middlewares_1 = require("../middlewares");
|
|
21
|
+
const generateResource_1 = __importDefault(require("./lib/generateResource"));
|
|
22
|
+
const buildHtml_1 = require("./lib/buildHtml");
|
|
9
23
|
const server_1 = __importDefault(require("./server"));
|
|
24
|
+
function getServerEntry() {
|
|
25
|
+
return {
|
|
26
|
+
[service_1.BUILD_SERVER_FILE_SERVER]: [(0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/server')]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
10
29
|
var lib_1 = require("./lib");
|
|
11
30
|
Object.defineProperty(exports, "getPageMiddleware", { enumerable: true, get: function () { return lib_1.getPageMiddleware; } });
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
name
|
|
17
|
-
|
|
18
|
-
|
|
31
|
+
/** This plugin uses `platformContext` so that it is set to a plugin getter */
|
|
32
|
+
const getPlugin = (platformContext) => {
|
|
33
|
+
const core = (0, service_1.createPlugin)({
|
|
34
|
+
configWebpack: (chain, { name }) => {
|
|
35
|
+
if (name === constants_1.BUNDLER_DEFAULT_TARGET) {
|
|
36
|
+
chain.merge({
|
|
37
|
+
entry: {
|
|
38
|
+
[service_1.BUILD_CLIENT_RUNTIME_POLYFILL]: ['@shuvi/app/core/polyfill'],
|
|
39
|
+
[service_1.BUILD_CLIENT_RUNTIME_MAIN]: [
|
|
40
|
+
(0, paths_1.resolvePkgFile)('esm/shuvi-app/entry/client')
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return chain;
|
|
46
|
+
},
|
|
47
|
+
addExtraTarget: ({ createConfig }, context) => {
|
|
48
|
+
const serverWebpackHelpers = (0, config_1.webpackHelpers)();
|
|
49
|
+
const serverChain = createConfig({
|
|
50
|
+
name: constants_1.BUNDLER_TARGET_SERVER,
|
|
51
|
+
node: true,
|
|
52
|
+
entry: getServerEntry(),
|
|
53
|
+
outputDir: service_1.BUILD_SERVER_DIR,
|
|
54
|
+
webpackHelpers: serverWebpackHelpers
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
name: constants_1.BUNDLER_TARGET_SERVER,
|
|
58
|
+
chain: serverChain
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
addRuntimeFile: ({ defineFile }, context) => {
|
|
62
|
+
const { config: { router: { history } } } = context;
|
|
63
|
+
const routerConfigFile = defineFile({
|
|
64
|
+
name: 'routerConfig.js',
|
|
65
|
+
content: () => {
|
|
66
|
+
return `export const historyMode = "${history}";`;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return [routerConfigFile];
|
|
70
|
+
},
|
|
71
|
+
addRuntimeService: () => [
|
|
72
|
+
{
|
|
73
|
+
source: (0, paths_1.resolvePkgFile)('esm/shuvi-app/shuvi-runtime-index'),
|
|
74
|
+
exported: '*'
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
source: (0, paths_1.resolvePkgFile)('lib/node/shuvi-runtime-server'),
|
|
78
|
+
filepath: 'server.ts',
|
|
79
|
+
exported: '*'
|
|
19
80
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
81
|
+
],
|
|
82
|
+
addResource: context => (0, generateResource_1.default)(context),
|
|
83
|
+
afterBuild: (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
yield (0, buildHtml_1.buildHtml)({
|
|
85
|
+
context,
|
|
86
|
+
serverPlugins: platformContext.serverPlugins,
|
|
87
|
+
getMiddlewares: middlewares_1.getMiddlewares,
|
|
88
|
+
pathname: '/',
|
|
89
|
+
filename: 'index.html'
|
|
90
|
+
});
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
return {
|
|
94
|
+
core,
|
|
95
|
+
server: server_1.default,
|
|
96
|
+
types: (0, paths_1.resolvePkgFile)('lib/node/features/html-render/shuvi-app.d.ts')
|
|
97
|
+
};
|
|
28
98
|
};
|
|
99
|
+
exports.getPlugin = getPlugin;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { IManifest } from '@shuvi/toolpack/lib/webpack/types';
|
|
2
|
-
import {
|
|
3
|
-
export default function generateFilesByRoutId(assetMap: IManifest, routes:
|
|
2
|
+
import { IPageRouteRecord } from '@shuvi/platform-shared/shared';
|
|
3
|
+
export default function generateFilesByRoutId(assetMap: IManifest, routes: IPageRouteRecord[]): Record<string, string[]>;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
function generateFilesByRoutId(assetMap, routes) {
|
|
4
4
|
let filesByRoutId = {};
|
|
5
5
|
const loadable = assetMap.loadble;
|
|
6
|
-
routes.forEach(({ id,
|
|
7
|
-
if (
|
|
8
|
-
filesByRoutId[id] = loadable[
|
|
6
|
+
routes.forEach(({ id, __componentRawRequest__ }) => {
|
|
7
|
+
if (__componentRawRequest__) {
|
|
8
|
+
filesByRoutId[id] = loadable[__componentRawRequest__].files;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
return filesByRoutId;
|
|
File without changes
|
|
File without changes
|
|
@@ -14,10 +14,8 @@ 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
21
|
__exportStar(require("./pageLoader"), exports);
|
|
@@ -11,38 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.renderToHTML = void 0;
|
|
13
13
|
const resources_1 = require("@shuvi/service/lib/resources");
|
|
14
|
-
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
15
14
|
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
15
|
function renderToHTML({ req, serverPluginContext }) {
|
|
47
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
17
|
let result;
|
|
@@ -54,23 +23,11 @@ function renderToHTML({ req, serverPluginContext }) {
|
|
|
54
23
|
});
|
|
55
24
|
try {
|
|
56
25
|
yield app.init();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
app:
|
|
60
|
-
|
|
26
|
+
result = yield renderer.renderView({
|
|
27
|
+
req,
|
|
28
|
+
app: app.getPublicAPI(),
|
|
29
|
+
ssr: serverPluginContext.config.ssr
|
|
61
30
|
});
|
|
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
31
|
}
|
|
75
32
|
finally {
|
|
76
33
|
yield app.dispose();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { IAppData
|
|
1
|
+
import { IAppData } from '@shuvi/platform-shared/shared';
|
|
2
2
|
import { IServerPluginContext } from '@shuvi/service';
|
|
3
|
-
import {
|
|
4
|
-
import { IRendererConstructorOptions,
|
|
3
|
+
import { IHtmlTag, IApplication } from './types';
|
|
4
|
+
import { IRendererConstructorOptions, IRenderViewOptions, IRenderDocumentResult } from './types';
|
|
5
5
|
export declare type AppData = Omit<IAppData, 'filesByRoutId' | 'publicPath'>;
|
|
6
6
|
export declare abstract class BaseRenderer {
|
|
7
7
|
protected _serverPluginContext: IServerPluginContext;
|
|
8
8
|
protected _app?: IApplication;
|
|
9
9
|
constructor({ serverPluginContext }: IRendererConstructorOptions);
|
|
10
|
-
abstract renderDocument({ app, req }:
|
|
10
|
+
abstract renderDocument({ app, req }: IRenderViewOptions): IRenderDocumentResult;
|
|
11
11
|
protected _getMainAssetTags(): {
|
|
12
12
|
styles: IHtmlTag<any>[];
|
|
13
13
|
scripts: IHtmlTag<any>[];
|
|
@@ -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,14 +13,54 @@ 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
|
+
};
|
|
16
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
26
|
exports.Renderer = void 0;
|
|
18
27
|
const resources_1 = require("@shuvi/service/lib/resources");
|
|
28
|
+
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
19
29
|
const htmlTag_1 = require("./htmlTag");
|
|
20
30
|
const viewTemplate_1 = require("../viewTemplate");
|
|
21
31
|
const spa_1 = require("./spa");
|
|
22
32
|
const ssr_1 = require("./ssr");
|
|
33
|
+
const htmlTag_2 = require("./htmlTag");
|
|
23
34
|
__exportStar(require("./types"), exports);
|
|
35
|
+
function addEssentialTagsIfMissing(document) {
|
|
36
|
+
let hasMetaCharset = false;
|
|
37
|
+
let hasMetaViewport = false;
|
|
38
|
+
for (const { tagName, attrs } of document.headTags) {
|
|
39
|
+
if (hasMetaCharset && hasMetaViewport) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
if (tagName === 'meta') {
|
|
43
|
+
if (attrs.charset) {
|
|
44
|
+
hasMetaCharset = true;
|
|
45
|
+
}
|
|
46
|
+
else if (attrs.name === 'viewport') {
|
|
47
|
+
hasMetaViewport = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (!hasMetaCharset) {
|
|
52
|
+
document.headTags.unshift((0, htmlTag_2.tag)('meta', {
|
|
53
|
+
charset: 'utf-8'
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
if (!hasMetaViewport) {
|
|
57
|
+
document.headTags.unshift((0, htmlTag_2.tag)('meta', {
|
|
58
|
+
name: 'viewport',
|
|
59
|
+
content: 'width=device-width,minimum-scale=1,initial-scale=1'
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
return document;
|
|
63
|
+
}
|
|
24
64
|
class Renderer {
|
|
25
65
|
constructor(options) {
|
|
26
66
|
this._serverPluginContext = options.serverPluginContext;
|
|
@@ -28,13 +68,36 @@ class Renderer {
|
|
|
28
68
|
this._ssrRenderer = new ssr_1.SsrRenderer(options);
|
|
29
69
|
this._spaRenderer = new spa_1.SpaRenderer(options);
|
|
30
70
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
71
|
+
renderView(options) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
let result;
|
|
75
|
+
const { app } = options;
|
|
76
|
+
const doc = yield this._renderDocument(options);
|
|
77
|
+
if ((0, shared_1.isResponse)(doc)) {
|
|
78
|
+
result = doc;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
addEssentialTagsIfMissing(doc);
|
|
82
|
+
yield this._serverPluginContext.serverPluginRunner.modifyHtml(doc, app.context);
|
|
83
|
+
const htmlStr = this._renderDocumentToString(doc);
|
|
84
|
+
result = (0, shared_1.text)(htmlStr, {
|
|
85
|
+
status: (_b = (_a = app.error) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : 200
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
_renderDocument(options) {
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
// todo: fallback to spa
|
|
94
|
+
if (options.ssr) {
|
|
95
|
+
return yield this._ssrRenderer.renderDocument(options);
|
|
96
|
+
}
|
|
97
|
+
return yield this._spaRenderer.renderDocument(options);
|
|
98
|
+
});
|
|
36
99
|
}
|
|
37
|
-
|
|
100
|
+
_renderDocumentToString(document, templateData = {}) {
|
|
38
101
|
const htmlAttrs = (0, htmlTag_1.stringifyAttrs)(document.htmlAttrs);
|
|
39
102
|
const head = document.headTags.map(tag => (0, htmlTag_1.stringifyTag)(tag)).join('');
|
|
40
103
|
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({ app }: IRenderViewOptions): IHtmlDocument;
|
|
5
5
|
}
|
|
@@ -5,11 +5,9 @@ const base_1 = require("./base");
|
|
|
5
5
|
class SpaRenderer extends base_1.BaseRenderer {
|
|
6
6
|
renderDocument({ app }) {
|
|
7
7
|
const assets = this._getMainAssetTags();
|
|
8
|
-
const serverPluginContext = this._serverPluginContext;
|
|
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
|
}
|
|
@@ -19,7 +19,7 @@ const htmlTag_1 = require("./htmlTag");
|
|
|
19
19
|
class SsrRenderer extends base_1.BaseRenderer {
|
|
20
20
|
renderDocument({ app, req }) {
|
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const { router, context } = app;
|
|
22
|
+
const { store, router, context } = app;
|
|
23
23
|
const serverPluginContext = this._serverPluginContext;
|
|
24
24
|
const { view } = resources_1.server;
|
|
25
25
|
const { getAssetPublicUrl } = serverPluginContext;
|
|
@@ -41,7 +41,7 @@ class SsrRenderer extends base_1.BaseRenderer {
|
|
|
41
41
|
Object.assign(acc, data);
|
|
42
42
|
return acc;
|
|
43
43
|
}, {});
|
|
44
|
-
const appData = Object.assign(Object.assign({}, result.appData), {
|
|
44
|
+
const appData = Object.assign(Object.assign({}, result.appData), { ssr: true, appState: store.getState(), pageData });
|
|
45
45
|
appData.runtimeConfig = (0, shuvi_singleton_runtimeConfig_1.getPublicRuntimeConfig)() || {};
|
|
46
46
|
const document = {
|
|
47
47
|
htmlAttrs: Object.assign({}, result.htmlAttrs),
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import { IApplication, IRequest } from '@shuvi/platform-shared/shared';
|
|
2
|
-
import { IHtmlAttrs, IHtmlTag, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer, IRenderAppServerResult } from '../../../../../shared';
|
|
1
|
+
import { IApplication, IRequest, Response } from '@shuvi/platform-shared/shared';
|
|
3
2
|
import { IServerPluginContext } from '@shuvi/service';
|
|
3
|
+
import { IHtmlAttrs, IHtmlTag, IClientRendererOptions, IServerRendererOptions, IViewClient, IViewServer, IRenderAppServerResult } from '../../../../../shared';
|
|
4
4
|
export { IHtmlAttrs, IHtmlTag, IApplication };
|
|
5
5
|
export interface IRendererConstructorOptions {
|
|
6
6
|
serverPluginContext: IServerPluginContext;
|
|
7
7
|
}
|
|
8
|
-
export declare type
|
|
8
|
+
export declare type IRenderViewOptions = {
|
|
9
9
|
app: IApplication;
|
|
10
10
|
req: IRequest;
|
|
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 };
|
|
@@ -1,32 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { IPlatformContext, ResolvedPlugin } from '@shuvi/service/lib/core';
|
|
2
|
+
export { buildHtml } from './html-render/lib/buildHtml';
|
|
2
3
|
export { getMiddlewares, getMiddlewaresBeforeDevMiddlewares } from './middlewares';
|
|
3
|
-
export
|
|
4
|
-
export declare const featurePlugins: (import("@shuvi/hook").IPluginInstance<{
|
|
5
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
6
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
7
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
8
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
9
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
10
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
11
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
12
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
13
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
14
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
15
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
16
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext> | {
|
|
17
|
-
core: import("@shuvi/hook").IPluginInstance<{
|
|
18
|
-
extendConfig: import("@shuvi/hook").SyncWaterfallHook<import("@shuvi/service").Config, void>;
|
|
19
|
-
afterInit: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
20
|
-
afterBuild: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
21
|
-
afterDestroy: import("@shuvi/hook").AsyncParallelHook<void, void, void>;
|
|
22
|
-
afterBundlerDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerDoneExtra, void, void>;
|
|
23
|
-
afterBundlerTargetDone: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").BundlerTargetDoneExtra, void, void>;
|
|
24
|
-
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
25
|
-
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
26
|
-
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
27
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOptions<any, any> | import("@shuvi/service/lib/project/index").FileOptions<any, any>[]>;
|
|
28
|
-
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
29
|
-
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
30
|
-
} | {
|
|
31
|
-
server: import("@shuvi/hook").IPluginInstance<import("@shuvi/service/lib/server/plugin").BuiltInServerPluginHooks & import("@shuvi/service/lib/server/pluginTypes").CustomServerPluginHooks, import("@shuvi/service").IServerPluginContext>;
|
|
32
|
-
})[];
|
|
4
|
+
export declare const getPlugins: (platformContext: IPlatformContext) => ResolvedPlugin[];
|
|
@@ -3,23 +3,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getPlugins = exports.getMiddlewaresBeforeDevMiddlewares = exports.getMiddlewares = exports.buildHtml = void 0;
|
|
7
7
|
const on_demand_compile_page_1 = __importDefault(require("./on-demand-compile-page"));
|
|
8
|
-
const html_render_1 =
|
|
8
|
+
const html_render_1 = require("./html-render");
|
|
9
9
|
const custom_server_1 = __importDefault(require("./custom-server"));
|
|
10
10
|
const model_1 = __importDefault(require("./model"));
|
|
11
11
|
const filesystem_routes_1 = __importDefault(require("./filesystem-routes"));
|
|
12
|
-
var buildHtml_1 = require("./
|
|
12
|
+
var buildHtml_1 = require("./html-render/lib/buildHtml");
|
|
13
13
|
Object.defineProperty(exports, "buildHtml", { enumerable: true, get: function () { return buildHtml_1.buildHtml; } });
|
|
14
14
|
var middlewares_1 = require("./middlewares");
|
|
15
15
|
Object.defineProperty(exports, "getMiddlewares", { enumerable: true, get: function () { return middlewares_1.getMiddlewares; } });
|
|
16
16
|
Object.defineProperty(exports, "getMiddlewaresBeforeDevMiddlewares", { enumerable: true, get: function () { return middlewares_1.getMiddlewaresBeforeDevMiddlewares; } });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
exports.featurePlugins = [
|
|
17
|
+
const getPlugins = (platformContext) => [
|
|
18
|
+
(0, html_render_1.getPlugin)(platformContext),
|
|
20
19
|
on_demand_compile_page_1.default,
|
|
21
20
|
filesystem_routes_1.default,
|
|
22
|
-
html_render_1.default,
|
|
23
21
|
custom_server_1.default,
|
|
24
22
|
model_1.default
|
|
25
23
|
];
|
|
24
|
+
exports.getPlugins = getPlugins;
|
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
configWebpack: import("@shuvi/hook").AsyncSeriesWaterfallHook<import("@shuvi/service/lib/core/lifecycleTypes").WebpackChainType, import("@shuvi/service/lib/core/lifecycleTypes").ConfigWebpackAssistant>;
|
|
10
10
|
addExtraTarget: import("@shuvi/hook").AsyncParallelHook<import("@shuvi/service/lib/core/lifecycleTypes").ExtraTargetAssistant, void, import("@shuvi/service/lib/core/lifecycleTypes").TargetChain>;
|
|
11
11
|
addResource: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").Resources | import("@shuvi/service/lib/core/lifecycleTypes").Resources[]>;
|
|
12
|
-
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").
|
|
12
|
+
addRuntimeFile: import("@shuvi/hook").AsyncParallelHook<void, import("@shuvi/service/lib/core/lifecycleTypes").AddRuntimeFileUtils, import("@shuvi/service/lib/project/index").FileOption<any, any> | import("@shuvi/service/lib/project/index").FileOption<any, any>[]>;
|
|
13
13
|
addRuntimeService: import("@shuvi/hook").AsyncParallelHook<void, void, import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService | import("@shuvi/service/lib/core/lifecycleTypes").RuntimeService[]>;
|
|
14
14
|
} & import("@shuvi/service/lib/core/apiTypes").CustomCorePluginHooks, import("@shuvi/service").IPluginContext>;
|
|
15
15
|
runtime: {
|
|
@@ -4,10 +4,5 @@ export declare type InitRedox = (params: {
|
|
|
4
4
|
initialState: any;
|
|
5
5
|
ctx: IAppContext;
|
|
6
6
|
}) => IStoreManager;
|
|
7
|
-
declare module '@shuvi/runtime' {
|
|
8
|
-
interface CustomAppContext {
|
|
9
|
-
storeManager?: IStoreManager;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
7
|
declare const _default: import("@shuvi/platform-shared/shared").IPluginInstance<import("@shuvi/platform-shared/shared").BuiltInRuntimePluginHooks & import("@shuvi/runtime").CustomRuntimePluginHooks, void>;
|
|
13
8
|
export default _default;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const redox_1 = require("@shuvi/redox");
|
|
4
4
|
const shared_1 = require("@shuvi/platform-shared/shared");
|
|
5
|
-
let
|
|
5
|
+
let currentStore;
|
|
6
6
|
const isServer = typeof window === 'undefined';
|
|
7
7
|
// for client, singleton mode
|
|
8
8
|
// for server, return new store
|
|
@@ -21,27 +21,21 @@ const initStore = ({ initialState, ctx }) => {
|
|
|
21
21
|
return createStoreInstance();
|
|
22
22
|
}
|
|
23
23
|
// for client is singleton, just init once
|
|
24
|
-
if (
|
|
25
|
-
|
|
24
|
+
if (!currentStore) {
|
|
25
|
+
currentStore = createStoreInstance();
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
return currentStoreManager;
|
|
27
|
+
return currentStore;
|
|
29
28
|
};
|
|
30
29
|
exports.default = (0, shared_1.createRuntimePlugin)({
|
|
31
30
|
appContext: ctx => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
initialState = (0, shared_1.getPageData)('redox');
|
|
36
|
-
}
|
|
37
|
-
if (ctx.pageData && ctx.pageData.redox) {
|
|
38
|
-
initialState = ctx.pageData.redox;
|
|
39
|
-
}
|
|
40
|
-
ctx.storeManager = initStore({
|
|
41
|
-
ctx,
|
|
42
|
-
initialState
|
|
43
|
-
});
|
|
31
|
+
let initialState = {};
|
|
32
|
+
if (!isServer) {
|
|
33
|
+
initialState = (0, shared_1.getPageData)('shuviInitialState', {});
|
|
44
34
|
}
|
|
35
|
+
ctx.store = initStore({
|
|
36
|
+
ctx,
|
|
37
|
+
initialState
|
|
38
|
+
});
|
|
45
39
|
return ctx;
|
|
46
40
|
}
|
|
47
41
|
});
|
|
@@ -3,10 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const service_1 = require("@shuvi/service");
|
|
4
4
|
exports.default = (0, service_1.createServerPlugin)({
|
|
5
5
|
getPageData: appContext => {
|
|
6
|
-
const {
|
|
7
|
-
delete appContext.storeManager;
|
|
6
|
+
const { store } = appContext;
|
|
8
7
|
return {
|
|
9
|
-
|
|
8
|
+
shuviInitialState: store.getState()
|
|
10
9
|
};
|
|
11
10
|
}
|
|
12
11
|
});
|