next-bun-compile 0.10.1 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -28
- package/dist/adapter.js +8 -0
- package/dist/{index-hb6dh1nm.js → index-k3fkzeev.js} +462 -61
- package/dist/index.js +7 -3
- package/dist/runtime/serve.js +724 -0
- package/package.json +16 -8
- package/dist/cli.js +0 -19
package/README.md
CHANGED
|
@@ -23,45 +23,56 @@ bun add -D next-bun-compile
|
|
|
23
23
|
|
|
24
24
|
## Setup
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
next-bun-compile is a [Next.js Build Adapter](https://nextjs.org/docs/app/api-reference/config/next-config-js/adapterPath). Point `adapterPath` at it in `next.config.ts`:
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
29
|
import type { NextConfig } from "next";
|
|
30
30
|
|
|
31
31
|
const nextConfig: NextConfig = {
|
|
32
|
-
|
|
32
|
+
adapterPath: "next-bun-compile/adapter",
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
export default nextConfig;
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
Or enable it without touching the config at all:
|
|
39
39
|
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
"scripts": {
|
|
43
|
-
"build": "next build && next-bun-compile"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
40
|
+
```bash
|
|
41
|
+
NEXT_ADAPTER_PATH=next-bun-compile/adapter next build
|
|
46
42
|
```
|
|
47
43
|
|
|
44
|
+
No `output: "standalone"` needed — the adapter assembles its own traced
|
|
45
|
+
output tree.
|
|
46
|
+
|
|
47
|
+
> **Monorepos:** Next resolves `adapterPath` from its own package location.
|
|
48
|
+
> If `next-bun-compile` is a nested workspace dependency, resolve it from
|
|
49
|
+
> the app dir instead:
|
|
50
|
+
>
|
|
51
|
+
> ```ts
|
|
52
|
+
> import { createRequire } from "node:module";
|
|
53
|
+
> const req = createRequire(process.cwd() + "/");
|
|
54
|
+
> const nextConfig: NextConfig = {
|
|
55
|
+
> adapterPath: req.resolve("next-bun-compile/adapter"),
|
|
56
|
+
> };
|
|
57
|
+
> ```
|
|
58
|
+
|
|
48
59
|
## Usage
|
|
49
60
|
|
|
50
61
|
```bash
|
|
51
|
-
|
|
52
|
-
./server
|
|
62
|
+
next build # Builds Next.js + compiles to ./server, one command
|
|
63
|
+
./server # Starts on port 3000
|
|
53
64
|
```
|
|
54
65
|
|
|
55
|
-
The binary is fully self-contained — static assets, public files, and the Next.js server are all embedded. Just copy it anywhere and run.
|
|
66
|
+
The binary is fully self-contained — static assets, public files, prerendered pages, and the Next.js server are all embedded. Just copy it anywhere and run. Static assets and fully-static prerendered pages are served straight from memory; ISR and cache-component responses get an in-memory cache that Next's own revalidation invalidates.
|
|
56
67
|
|
|
57
68
|
### Cross-Compilation
|
|
58
69
|
|
|
59
|
-
|
|
70
|
+
Set `NBC_TARGET` to cross-compile for a different platform:
|
|
60
71
|
|
|
61
72
|
```bash
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
NBC_TARGET=bun-linux-x64 next build
|
|
74
|
+
NBC_TARGET=bun-linux-arm64 next build
|
|
75
|
+
NBC_TARGET=bun-windows-x64 next build
|
|
65
76
|
```
|
|
66
77
|
|
|
67
78
|
See the [Bun cross-compilation docs](https://bun.sh/docs/bundler/executables#cross-compile) for all available targets.
|
|
@@ -73,6 +84,8 @@ See the [Bun cross-compilation docs](https://bun.sh/docs/bundler/executables#cro
|
|
|
73
84
|
| `PORT` | `3000` | Server port |
|
|
74
85
|
| `HOSTNAME` | `0.0.0.0` | Server hostname |
|
|
75
86
|
| `KEEP_ALIVE_TIMEOUT` | — | HTTP keep-alive timeout (ms) |
|
|
87
|
+
| `NBC_RUNTIME_DIR` | binary's directory | Where runtime files extract and `.next/cache` lives. Point at tmpfs (e.g. `/tmp/app`) for RAM-backed runtime files and read-only root filesystems |
|
|
88
|
+
| `NBC_TARGET` | host platform | Cross-compile target (build time) |
|
|
76
89
|
|
|
77
90
|
### CDN / `assetPrefix`
|
|
78
91
|
|
|
@@ -80,7 +93,7 @@ If you configure `assetPrefix` in your `next.config.ts`, static assets (`/_next/
|
|
|
80
93
|
|
|
81
94
|
```ts
|
|
82
95
|
const nextConfig: NextConfig = {
|
|
83
|
-
|
|
96
|
+
adapterPath: "next-bun-compile/adapter",
|
|
84
97
|
assetPrefix: "https://cdn.example.com",
|
|
85
98
|
};
|
|
86
99
|
```
|
|
@@ -117,16 +130,6 @@ Some modules can't be resolved at compile time but are never reached in producti
|
|
|
117
130
|
|
|
118
131
|
## Troubleshooting
|
|
119
132
|
|
|
120
|
-
### Stale standalone output after upgrading Next.js
|
|
121
|
-
|
|
122
|
-
Next.js doesn't clean the standalone output directory between builds. If you upgrade Next.js versions, stale files from the old version can cause runtime errors like `Cannot find module 'next/dist/compiled/source-map'`.
|
|
123
|
-
|
|
124
|
-
**Fix:** Clean the standalone output before rebuilding:
|
|
125
|
-
|
|
126
|
-
```bash
|
|
127
|
-
rm -rf .next/standalone && bun next build && next-bun-compile
|
|
128
|
-
```
|
|
129
|
-
|
|
130
133
|
### Packages with dynamic `require()` calls (e.g. pino)
|
|
131
134
|
|
|
132
135
|
Some packages like `pino` use dynamic `require()` calls internally (for worker threads, transports, etc.). Turbopack can't resolve these at build time, so they fail at runtime inside the compiled binary with errors like:
|
|
@@ -139,7 +142,7 @@ Failed to load external module pino-142500b1eb3f4baf: Cannot find package ...
|
|
|
139
142
|
|
|
140
143
|
```ts
|
|
141
144
|
const nextConfig: NextConfig = {
|
|
142
|
-
|
|
145
|
+
adapterPath: "next-bun-compile/adapter",
|
|
143
146
|
transpilePackages: ["pino", "pino-pretty"],
|
|
144
147
|
};
|
|
145
148
|
```
|