This commit is contained in:
Benjamin Toby 2026-03-17 04:56:01 +01:00
parent 19d0ceb7db
commit cefcad9b76
3 changed files with 31 additions and 5 deletions

View File

@ -23,6 +23,12 @@ export default function () {
allPagesBundler({
exit_after_first_build: true,
// async post_build_fn({ artifacts }) {
// writeFileSync(
// HYDRATION_DST_DIR_MAP_JSON_FILE,
// JSON.stringify(artifacts),
// );
// },
});
});
}

View File

@ -12,7 +12,8 @@ import type { BundlerCTXMap } from "../../types";
import { execSync } from "child_process";
import grabConstants from "../../utils/grab-constants";
const { HYDRATION_DST_DIR, PAGES_DIR } = grabDirNames();
const { HYDRATION_DST_DIR, PAGES_DIR, HYDRATION_DST_DIR_MAP_JSON_FILE } =
grabDirNames();
const tailwindPlugin: esbuild.Plugin = {
name: "tailwindcss",
@ -151,11 +152,16 @@ export default async function allPagesBundler(params?: Params) {
console.timeEnd("build");
writeFileSync(
HYDRATION_DST_DIR_MAP_JSON_FILE,
JSON.stringify(artifacts),
);
if (params?.exit_after_first_build) {
console.log(
"global.BUNDLER_CTX_MAP",
global.BUNDLER_CTX_MAP,
);
// console.log(
// "global.BUNDLER_CTX_MAP",
// global.BUNDLER_CTX_MAP,
// );
process.exit();
}
});

View File

@ -4,6 +4,12 @@ import allPagesBundler from "../bundler/all-pages-bundler";
import serverParamsGen from "./server-params-gen";
import watcher from "./watcher";
import serverPostBuildFn from "./server-post-build-fn";
import grabDirNames from "../../utils/grab-dir-names";
import EJSON from "../../utils/ejson";
import { readFileSync } from "fs";
import type { BundlerCTXMap } from "../../types";
const { HYDRATION_DST_DIR_MAP_JSON_FILE } = grabDirNames();
type Params = {
dev?: boolean;
@ -21,6 +27,14 @@ export default async function startServer(params?: Params) {
});
watcher();
} else {
const artifacts = EJSON.parse(
readFileSync(HYDRATION_DST_DIR_MAP_JSON_FILE, "utf-8"),
) as BundlerCTXMap[] | undefined;
if (!artifacts?.[0]) {
console.error(`Please build first.`);
process.exit(1);
}
global.BUNDLER_CTX_MAP = artifacts;
global.IS_FIRST_BUNDLE_READY = true;
}