nuxt-bun-compile 0.1.24 → 0.1.26
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 +107 -0
- package/README.ptBR.md +107 -0
- package/dist/module.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,7 @@ The module hooks into Nuxt's build pipeline and handles **everything** automatic
|
|
|
68
68
|
| `enabled` | `boolean` | `true` | Enable/disable the module |
|
|
69
69
|
| `outfile` | `string` | `"nuxtbin"` | Output binary filename |
|
|
70
70
|
| `bunPath` | `string` | `undefined` | Path to the bun executable. Can be a directory (e.g., `/opt/bun/`) or a direct path to the binary (e.g., `/opt/bun/bun`). If it's a directory, '/bun' will be appended. Defaults to 'bun' from the system's PATH. |
|
|
71
|
+
| `target` | `'bun-linux-x64' \| 'bun-linux-x64-musl' \| 'bun-linux-arm64' \| 'bun-linux-arm64-musl'` | `auto-detected` | Target platform for binary compilation. Auto-detects your system architecture (x64/arm64) and libc type (glibc/musl). Override only if auto-detection fails or you need a specific target. |
|
|
71
72
|
| `extraExternals` | `(string \| RegExp)[]` | `[]` | Additional packages to mark as external |
|
|
72
73
|
| `autoCompile` | `boolean` | `true` | Run `bun build --compile` automatically after build |
|
|
73
74
|
|
|
@@ -98,6 +99,32 @@ bunCompile: {
|
|
|
98
99
|
|
|
99
100
|
---
|
|
100
101
|
|
|
102
|
+
## ⚠️ Native Dependencies in Alpine Linux
|
|
103
|
+
|
|
104
|
+
When compiling with `--target=bun-linux-x64-musl` or `--target=bun-linux-arm64-musl` (Alpine), the resulting binary still dynamically links to `libstdc++` and `libgcc` at runtime. This is documented Bun behavior:
|
|
105
|
+
|
|
106
|
+
- [oven-sh/bun#23910](https://github.com/oven-sh/bun/issues/23910)
|
|
107
|
+
- [oven-sh/bun#918](https://github.com/oven-sh/bun/issues/918)
|
|
108
|
+
|
|
109
|
+
### Solution: Install Required Libraries in Docker
|
|
110
|
+
|
|
111
|
+
If running the binary in an Alpine Linux container, install the required libraries:
|
|
112
|
+
|
|
113
|
+
```dockerfile
|
|
114
|
+
FROM alpine:latest
|
|
115
|
+
|
|
116
|
+
RUN apk add --no-cache libstdc++ libgcc
|
|
117
|
+
|
|
118
|
+
COPY nuxtbin /app/
|
|
119
|
+
WORKDIR /app
|
|
120
|
+
|
|
121
|
+
CMD ["./nuxtbin"]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This ensures all runtime dependencies are available in the container.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
101
128
|
## 🏗️ Architecture
|
|
102
129
|
|
|
103
130
|
The module uses a **hook-based architecture**:
|
|
@@ -145,6 +172,86 @@ The **`-b`** (or `--bun`) flag forces Bun to be the runtime that executes the sc
|
|
|
145
172
|
|
|
146
173
|
---
|
|
147
174
|
|
|
175
|
+
## 📚 Usage Examples
|
|
176
|
+
|
|
177
|
+
### Custom Build Script
|
|
178
|
+
|
|
179
|
+
Create a dedicated npm script in your `package.json`:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"scripts": {
|
|
184
|
+
"build": "nuxt build",
|
|
185
|
+
"compile": "NODE_OPTIONS=\"--max-old-space-size=8192\" bun run -b build"
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Then run: `bun run compile`
|
|
191
|
+
|
|
192
|
+
### Docker Deployment
|
|
193
|
+
|
|
194
|
+
Before building, create a `.dockerignore` file to exclude unnecessary files from the build context:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
.claude
|
|
198
|
+
.devcontainer
|
|
199
|
+
.gemini
|
|
200
|
+
.git
|
|
201
|
+
.github
|
|
202
|
+
.husky
|
|
203
|
+
.nuxt
|
|
204
|
+
.output
|
|
205
|
+
.serena
|
|
206
|
+
.vscode
|
|
207
|
+
.yarn
|
|
208
|
+
dist
|
|
209
|
+
node_modules
|
|
210
|
+
nuxtbin
|
|
211
|
+
test
|
|
212
|
+
tests
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Deploy the compiled binary in a Docker container using multi-stage build:
|
|
216
|
+
|
|
217
|
+
```dockerfile
|
|
218
|
+
# Stage 1: Base image with Bun runtime
|
|
219
|
+
FROM oven/bun:alpine AS bun-base
|
|
220
|
+
WORKDIR /app
|
|
221
|
+
|
|
222
|
+
# Stage 2: Install dependencies
|
|
223
|
+
FROM bun-base AS bun-install
|
|
224
|
+
COPY package.json bun.lockb ./
|
|
225
|
+
RUN bun install --frozen-lockfile
|
|
226
|
+
|
|
227
|
+
# Stage 3: Build the binary
|
|
228
|
+
FROM bun-base AS bun-build
|
|
229
|
+
COPY --from=bun-install /app/node_modules /app/node_modules
|
|
230
|
+
COPY . .
|
|
231
|
+
RUN NODE_OPTIONS="--max-old-space-size=8192" bun run -b build
|
|
232
|
+
|
|
233
|
+
# Stage 4: Release (lightweight production image)
|
|
234
|
+
FROM alpine:latest AS release
|
|
235
|
+
EXPOSE 3000/tcp
|
|
236
|
+
WORKDIR /app
|
|
237
|
+
# Required libraries for Bun binaries on Alpine
|
|
238
|
+
# See: https://github.com/oven-sh/bun/issues/23910
|
|
239
|
+
# https://github.com/oven-sh/bun/issues/918
|
|
240
|
+
RUN apk add --no-cache libstdc++ libgcc
|
|
241
|
+
COPY --from=bun-build /app/nuxtbin /app/nuxtbin
|
|
242
|
+
CMD ["./nuxtbin"]
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Build and run:
|
|
246
|
+
```bash
|
|
247
|
+
docker build -t my-nuxt-app .
|
|
248
|
+
docker run -p 3000:3000 my-nuxt-app
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
> **Reference:** See the complete multi-stage example in [nuxt-duckdb-wasm/Dockerfile](https://github.com/jprando/nuxt-duckdb-wasm/blob/main/Dockerfile) for a production-ready setup.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
148
255
|
## 🧑💻 Development
|
|
149
256
|
|
|
150
257
|
### Testing Locally in a Nuxt App
|
package/README.ptBR.md
CHANGED
|
@@ -68,6 +68,7 @@ O módulo se conecta ao pipeline de build do Nuxt e cuida de **tudo** automatica
|
|
|
68
68
|
| `enabled` | `boolean` | `true` | Habilitar/desabilitar o módulo |
|
|
69
69
|
| `outfile` | `string` | `"nuxtbin"` | Nome do arquivo binário de saída |
|
|
70
70
|
| `bunPath` | `string` | `undefined` | Caminho para o executável do bun. Pode ser um diretório (ex: `/opt/bun/`) ou o caminho direto para o binário (ex: `/opt/bun/bun`). Se for um diretório, '/bun' será anexado. O padrão é 'bun' do PATH do sistema. |
|
|
71
|
+
| `target` | `'bun-linux-x64' \| 'bun-linux-x64-musl' \| 'bun-linux-arm64' \| 'bun-linux-arm64-musl'` | `auto-detectado` | Plataforma alvo para compilação do binário. Auto-detecta sua arquitetura (x64/arm64) e tipo de libc (glibc/musl). Sobrescreva apenas se a auto-detecção falhar ou você precisar de um target específico. |
|
|
71
72
|
| `extraExternals` | `(string \| RegExp)[]` | `[]` | Pacotes adicionais para marcar como external |
|
|
72
73
|
| `autoCompile` | `boolean` | `true` | Executar `bun build --compile` automaticamente após o build |
|
|
73
74
|
|
|
@@ -98,6 +99,32 @@ bunCompile: {
|
|
|
98
99
|
|
|
99
100
|
---
|
|
100
101
|
|
|
102
|
+
## ⚠️ Dependências Nativas no Alpine Linux
|
|
103
|
+
|
|
104
|
+
Ao compilar com `--target=bun-linux-x64-musl` ou `--target=bun-linux-arm64-musl` (Alpine), o binário resultante ainda faz link dinâmico com `libstdc++` e `libgcc` em tempo de execução. Este é um comportamento documentado do Bun:
|
|
105
|
+
|
|
106
|
+
- [oven-sh/bun#23910](https://github.com/oven-sh/bun/issues/23910)
|
|
107
|
+
- [oven-sh/bun#918](https://github.com/oven-sh/bun/issues/918)
|
|
108
|
+
|
|
109
|
+
### Solução: Instalar Bibliotecas Necessárias no Docker
|
|
110
|
+
|
|
111
|
+
Se rodar o binário em um container Alpine Linux, instale as bibliotecas necessárias:
|
|
112
|
+
|
|
113
|
+
```dockerfile
|
|
114
|
+
FROM alpine:latest
|
|
115
|
+
|
|
116
|
+
RUN apk add --no-cache libstdc++ libgcc
|
|
117
|
+
|
|
118
|
+
COPY nuxtbin /app/
|
|
119
|
+
WORKDIR /app
|
|
120
|
+
|
|
121
|
+
CMD ["./nuxtbin"]
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Isso garante que todas as dependências de runtime estejam disponíveis no container.
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
101
128
|
## 🏗️ Arquitetura
|
|
102
129
|
|
|
103
130
|
O módulo usa uma **arquitetura baseada em hooks**:
|
|
@@ -145,6 +172,86 @@ O parâmetro **`-b`** (ou `--bun`) força o Bun a ser o runtime que executa o sc
|
|
|
145
172
|
|
|
146
173
|
---
|
|
147
174
|
|
|
175
|
+
## 📚 Exemplos de Uso
|
|
176
|
+
|
|
177
|
+
### Script Customizado de Build
|
|
178
|
+
|
|
179
|
+
Crie um script npm/bun dedicado no seu `package.json`:
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"scripts": {
|
|
184
|
+
"build": "nuxt build",
|
|
185
|
+
"compile": "NODE_OPTIONS=\"--max-old-space-size=8192\" bun run -b build"
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Execute com: `bun run compile`
|
|
191
|
+
|
|
192
|
+
### Deploy com Docker
|
|
193
|
+
|
|
194
|
+
Antes de compilar, crie um arquivo `.dockerignore` para excluir arquivos desnecessários do contexto de build:
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
.claude
|
|
198
|
+
.devcontainer
|
|
199
|
+
.gemini
|
|
200
|
+
.git
|
|
201
|
+
.github
|
|
202
|
+
.husky
|
|
203
|
+
.nuxt
|
|
204
|
+
.output
|
|
205
|
+
.serena
|
|
206
|
+
.vscode
|
|
207
|
+
.yarn
|
|
208
|
+
dist
|
|
209
|
+
node_modules
|
|
210
|
+
nuxtbin
|
|
211
|
+
test
|
|
212
|
+
tests
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Faça deploy do binário compilado em um container Docker usando multi-stage build:
|
|
216
|
+
|
|
217
|
+
```dockerfile
|
|
218
|
+
# Estágio 1: Imagem base com runtime Bun
|
|
219
|
+
FROM oven/bun:alpine AS bun-base
|
|
220
|
+
WORKDIR /app
|
|
221
|
+
|
|
222
|
+
# Estágio 2: Instalar dependências
|
|
223
|
+
FROM bun-base AS bun-install
|
|
224
|
+
COPY package.json bun.lockb ./
|
|
225
|
+
RUN bun install --frozen-lockfile
|
|
226
|
+
|
|
227
|
+
# Estágio 3: Compilar o binário
|
|
228
|
+
FROM bun-base AS bun-build
|
|
229
|
+
COPY --from=bun-install /app/node_modules /app/node_modules
|
|
230
|
+
COPY . .
|
|
231
|
+
RUN NODE_OPTIONS="--max-old-space-size=8192" bun run -b build
|
|
232
|
+
|
|
233
|
+
# Estágio 4: Release (imagem de produção otimizada)
|
|
234
|
+
FROM alpine:latest AS release
|
|
235
|
+
EXPOSE 3000/tcp
|
|
236
|
+
WORKDIR /app
|
|
237
|
+
# Bibliotecas necessárias para binários Bun no Alpine
|
|
238
|
+
# Ver: https://github.com/oven-sh/bun/issues/23910
|
|
239
|
+
# https://github.com/oven-sh/bun/issues/918
|
|
240
|
+
RUN apk add --no-cache libstdc++ libgcc
|
|
241
|
+
COPY --from=bun-build /app/nuxtbin /app/nuxtbin
|
|
242
|
+
CMD ["./nuxtbin"]
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Build e execute:
|
|
246
|
+
```bash
|
|
247
|
+
docker build -t minha-app-nuxt .
|
|
248
|
+
docker run -p 3000:3000 minha-app-nuxt
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
> **Referência:** Veja um exemplo completo com multi-stage em [nuxt-duckdb-wasm/Dockerfile](https://github.com/jprando/nuxt-duckdb-wasm/blob/main/Dockerfile) para um setup pronto para produção.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
148
255
|
## 🧑💻 Desenvolvimento
|
|
149
256
|
|
|
150
257
|
### Testando Localmente em uma Aplicação Nuxt
|
package/dist/module.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-bun-compile",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"description": "Nuxt module that automatically configures Nitro for `bun build --compile`, generating a standalone executable binary from your Nuxt app.",
|
|
5
5
|
"repository": "jprando/nuxt-bun-compile",
|
|
6
6
|
"license": "MIT",
|