Add SSR bundle minify config
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { describe, it, expect, afterEach } from "bun:test";
|
||||
import shouldMinifySSR from "../../utils/should-minify-ssr";
|
||||
|
||||
const originalEnv = process.env.NODE_ENV;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.NODE_ENV = originalEnv;
|
||||
});
|
||||
|
||||
describe("shouldMinifySSR", () => {
|
||||
it("never minifies in development", () => {
|
||||
process.env.NODE_ENV = "development";
|
||||
expect(shouldMinifySSR()).toBe(false);
|
||||
expect(shouldMinifySSR({ minify_ssr_bundle: true })).toBe(false);
|
||||
expect(shouldMinifySSR({ minify_ssr_bundle: false })).toBe(false);
|
||||
});
|
||||
|
||||
it("minifies in production by default", () => {
|
||||
process.env.NODE_ENV = "production";
|
||||
expect(shouldMinifySSR()).toBe(true);
|
||||
expect(shouldMinifySSR({ minify_ssr_bundle: true })).toBe(true);
|
||||
});
|
||||
|
||||
it("skips minification when minify_ssr_bundle is false", () => {
|
||||
process.env.NODE_ENV = "production";
|
||||
expect(shouldMinifySSR({ minify_ssr_bundle: false })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -13,9 +13,8 @@ import { evictDeletedModules } from "../../utils/import-fresh";
|
||||
import { writeFileSync } from "fs";
|
||||
import path from "path";
|
||||
import { log } from "../../utils/log";
|
||||
import {
|
||||
logBuildErrorsOnce,
|
||||
} from "../../utils/build-error-log";
|
||||
import { logBuildErrorsOnce } from "../../utils/build-error-log";
|
||||
import shouldMinifySSR from "../../utils/should-minify-ssr";
|
||||
|
||||
const { BUNX_CWD_MODULE_CACHE_DIR, BUNX_TMP_DIR } = grabDirNames();
|
||||
|
||||
@@ -174,7 +173,9 @@ async function doSSRRebuild(params?: RebuildParams) {
|
||||
entryPoints,
|
||||
outdir: BUNX_CWD_MODULE_CACHE_DIR,
|
||||
bundle: true,
|
||||
minify: !dev,
|
||||
minify: shouldMinifySSR({
|
||||
minify_ssr_bundle: config.minify_ssr_bundle,
|
||||
}),
|
||||
format: "esm",
|
||||
target: "esnext",
|
||||
platform: "node",
|
||||
@@ -244,4 +245,4 @@ async function doSSRRebuild(params?: RebuildParams) {
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,6 +131,13 @@ export type BunextConfig = {
|
||||
* aborted and answered with a 500. Defaults to 30000.
|
||||
*/
|
||||
ssr_render_timeout_ms?: number;
|
||||
/**
|
||||
* Minify the SSR bundle. The SSR output is read off local disk by the
|
||||
* server and is never downloaded by a browser, so minifying it only costs
|
||||
* build memory. Set to `false` on memory-constrained hosts. Never minified
|
||||
* in dev; defaults to `true` in production.
|
||||
*/
|
||||
minify_ssr_bundle?: boolean;
|
||||
};
|
||||
|
||||
export type BunextConfigMiddlewareParams = {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import isDevelopment from "./is-development";
|
||||
|
||||
type Params = {
|
||||
/**
|
||||
* The value of `minify_ssr_bundle` in `bunext.config.ts`
|
||||
* (`global.BUNEXT_CONFIG.minify_ssr_bundle`).
|
||||
*/
|
||||
minify_ssr_bundle?: boolean;
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether the SSR bundle should be minified.
|
||||
*
|
||||
* The SSR output is read off local disk by the server and is never downloaded
|
||||
* by a browser, so minifying it only costs build memory. Dev is never minified.
|
||||
* In production the bundle is minified unless `minify_ssr_bundle` is explicitly
|
||||
* set to `false` in `bunext.config.ts`.
|
||||
*/
|
||||
export default function shouldMinifySSR(params: Params = {}): boolean {
|
||||
if (isDevelopment()) return false;
|
||||
return params.minify_ssr_bundle !== false;
|
||||
}
|
||||
Reference in New Issue
Block a user