Add SSR mode and test on Android

This commit is contained in:
pengfei.zhou
2022-11-02 14:29:07 +08:00
committed by osborn
parent 5782a0d161
commit c3b9638434
18 changed files with 313 additions and 61 deletions

View File

@@ -91,4 +91,25 @@ export async function mergeMap(mapFile: string) {
await fs.promises.unlink(lockFile)
}
}
export async function ssr() {
const ret = await build();
if (ret != 0) {
return ret;
}
console.log("Start generate ssr data");
const bundleFiles = await glob("bundle/**/*.js");
process.env["SSR_BUILD"] = "1";
for (let bundleFile of bundleFiles) {
console.log(bundleFile);
await Shell.exec("node", [bundleFile], {
env: process.env,
consoleHandler: (info) => {
console.log(info);
}
});
}
return 0;
}

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env node
import commander from "commander"
import { build, clean } from "./actions";
import { build, clean, ssr } from "./actions";
import { create, createLib } from "./create"
import dev from "./dev"
import { run } from "./run";
@@ -41,7 +41,18 @@ commander
.action(async function () {
await clean();
})
commander
.command('ssr <action>')
.action(async function (action) {
if (action === 'build') {
const ret = await ssr();
if (ret != 0) {
process.exit(ret)
}
} else {
console.error("Do not support in ssr mode ", action)
}
})
commander
.command('run <platform>')
.action(async function (platform, cmd) {