ssr
Version:
cli for react/vue2/vue3 ssr deploy on serverless or tradtional web server
33 lines • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ssg = void 0;
const fs_1 = require("fs");
const path_1 = require("path");
const ssg = async (argv) => {
if (!argv.ssg) {
return;
}
const { loadConfig, getCwd, logGreen } = await Promise.resolve().then(() => require('ssr-common-utils'));
const config = loadConfig();
const { chunkName } = config;
const cwd = getCwd();
const serverFile = (0, path_1.resolve)(cwd, `./build/server/${chunkName}.server.js`);
const { Routes, serverRender } = require(serverFile);
for (const item of Routes.FeRoutes) {
const { path, webpackChunkName } = item;
const mockCtx = {
request: {
path: path,
url: path
},
desc: "It's a mock context"
};
const res = await serverRender(mockCtx, Object.assign(config, { stream: false }));
const htmlStr = res.html || res;
const fileName = `./build/client/${webpackChunkName}.html`;
await fs_1.promises.writeFile((0, path_1.resolve)(cwd, fileName), htmlStr);
logGreen(`Component ${path} be mapped to ${fileName}`);
}
};
exports.ssg = ssg;
//# sourceMappingURL=ssg.js.map