Bugfix. Fix SSR pages filters. Remove dedicated API bundler, use SSR bundler for pages and api routes.
This commit is contained in:
+33
-31
@@ -8,35 +8,37 @@ const { BUNX_CWD_MODULE_CACHE_DIR } = grabDirNames();
|
||||
export default async function apiRoutesContextBundler() {
|
||||
const pages = grabAllPages({ api_only: true });
|
||||
const dev = isDevelopment();
|
||||
if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
await global.API_ROUTES_BUNDLER_CTX.dispose();
|
||||
global.API_ROUTES_BUNDLER_CTX = undefined;
|
||||
}
|
||||
global.API_ROUTES_BUNDLER_CTX = await esbuild.context({
|
||||
entryPoints: pages.map((p) => p.local_path),
|
||||
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
bundle: true,
|
||||
minify: !dev,
|
||||
format: "esm",
|
||||
target: "esnext",
|
||||
platform: "node",
|
||||
define: {
|
||||
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production"),
|
||||
},
|
||||
entryNames: "api/[dir]/[hash]",
|
||||
metafile: true,
|
||||
plugins: [
|
||||
tailwindEsbuildPlugin,
|
||||
apiRoutesCTXArtifactTracker({ pages }),
|
||||
],
|
||||
jsx: "automatic",
|
||||
external: [
|
||||
"react",
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
"bun:*",
|
||||
],
|
||||
});
|
||||
await global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
// if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
// await global.API_ROUTES_BUNDLER_CTX.dispose();
|
||||
// global.API_ROUTES_BUNDLER_CTX = undefined;
|
||||
// }
|
||||
// global.API_ROUTES_BUNDLER_CTX = await esbuild.context({
|
||||
// entryPoints: pages.map((p) => p.local_path),
|
||||
// outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
// bundle: true,
|
||||
// minify: !dev,
|
||||
// format: "esm",
|
||||
// target: "esnext",
|
||||
// platform: "node",
|
||||
// define: {
|
||||
// "process.env.NODE_ENV": JSON.stringify(
|
||||
// dev ? "development" : "production",
|
||||
// ),
|
||||
// },
|
||||
// entryNames: "api/[dir]/[hash]",
|
||||
// metafile: true,
|
||||
// plugins: [
|
||||
// tailwindEsbuildPlugin,
|
||||
// apiRoutesCTXArtifactTracker({ pages }),
|
||||
// ],
|
||||
// jsx: "automatic",
|
||||
// external: [
|
||||
// "react",
|
||||
// "react-dom",
|
||||
// "react/jsx-runtime",
|
||||
// "react/jsx-dev-runtime",
|
||||
// "bun:*",
|
||||
// ],
|
||||
// });
|
||||
// await global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ export default async function buildOnstartErrorHandler(params) {
|
||||
global.BUNDLER_CTX_DISPOSED = true;
|
||||
global.RECOMPILING = false;
|
||||
global.IS_SERVER_COMPONENT = false;
|
||||
await Promise.all([
|
||||
Promise.all([
|
||||
global.SSR_BUNDLER_CTX?.dispose(),
|
||||
global.BUNDLER_CTX?.dispose(),
|
||||
]);
|
||||
|
||||
+2
-1
@@ -9,7 +9,7 @@ import ssrVirtualFilesPlugin from "./plugins/ssr-virtual-files-plugin";
|
||||
import ssrCTXArtifactTracker from "./plugins/ssr-ctx-artifact-tracker";
|
||||
const { BUNX_CWD_MODULE_CACHE_DIR } = grabDirNames();
|
||||
export default async function pagesSSRContextBundler(params) {
|
||||
const pages = grabAllPages({ exclude_api: true });
|
||||
const pages = grabAllPages();
|
||||
const dev = isDevelopment();
|
||||
if (global.SSR_BUNDLER_CTX) {
|
||||
await global.SSR_BUNDLER_CTX.dispose();
|
||||
@@ -61,6 +61,7 @@ export default async function pagesSSRContextBundler(params) {
|
||||
"react-dom",
|
||||
"react/jsx-runtime",
|
||||
"react/jsx-dev-runtime",
|
||||
"bun:*",
|
||||
],
|
||||
// logLevel: "silent",
|
||||
});
|
||||
|
||||
@@ -44,17 +44,21 @@ export default function apiRoutesCTXArtifactTracker({ pages }) {
|
||||
url_path,
|
||||
};
|
||||
});
|
||||
if (artifacts?.[0] && artifacts.length > 0) {
|
||||
for (let i = 0; i < artifacts.length; i++) {
|
||||
const artifact = artifacts[i];
|
||||
if (artifact?.local_path &&
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP) {
|
||||
global.API_ROUTES_BUNDLER_CTX_MAP[artifact.local_path] = artifact;
|
||||
}
|
||||
}
|
||||
}
|
||||
// const elapsed = (performance.now() - build_start).toFixed(0);
|
||||
// log.success(`API Routes [Built] in ${elapsed}ms`);
|
||||
// if (artifacts?.[0] && artifacts.length > 0) {
|
||||
// for (let i = 0; i < artifacts.length; i++) {
|
||||
// const artifact = artifacts[i];
|
||||
// if (
|
||||
// artifact?.local_path &&
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP
|
||||
// ) {
|
||||
// global.API_ROUTES_BUNDLER_CTX_MAP[
|
||||
// artifact.local_path
|
||||
// ] = artifact;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
const elapsed = (performance.now() - build_start).toFixed(0);
|
||||
log.success(`API Routes [Built] in ${elapsed}ms`);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -48,12 +48,6 @@ export default function esbuildCTXArtifactTracker({ entryToPage, post_build_fn,
|
||||
else {
|
||||
pagesSSRContextBundler();
|
||||
}
|
||||
if (global.API_ROUTES_BUNDLER_CTX) {
|
||||
global.API_ROUTES_BUNDLER_CTX.rebuild();
|
||||
}
|
||||
else {
|
||||
apiRoutesContextBundler();
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {} from "esbuild";
|
||||
import grabArtifactsFromBundledResults from "../grab-artifacts-from-bundled-result";
|
||||
import buildOnstartErrorHandler from "../build-on-start-error-handler";
|
||||
import { log } from "../../../utils/log";
|
||||
let build_start = 0;
|
||||
let build_starts = 0;
|
||||
const MAX_BUILD_STARTS = 2;
|
||||
@@ -34,7 +35,11 @@ export default function ssrCTXArtifactTracker({ entryToPage, post_build_fn, }) {
|
||||
artifact;
|
||||
}
|
||||
}
|
||||
post_build_fn?.({ artifacts });
|
||||
// post_build_fn?.({ artifacts });
|
||||
// const elapsed = (performance.now() - build_start).toFixed(
|
||||
// 0,
|
||||
// );
|
||||
// log.success(`SSR [Built] in ${elapsed}ms`);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user