mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
--console & console: true (#19427)
Co-authored-by: Zack Radisic <56137411+zackradisic@users.noreply.github.com>
This commit is contained in:
@@ -203,6 +203,34 @@ When `development` is `true`, Bun will:
|
||||
- Include the `SourceMap` header in the response so that devtools can show the original source code
|
||||
- Disable minification
|
||||
- Re-bundle assets on each request to a .html file
|
||||
- Enable hot module reloading (unless `hmr: false` is set)
|
||||
|
||||
#### Echo console logs from browser to terminal
|
||||
|
||||
Bun.serve() supports echoing console logs from the browser to the terminal.
|
||||
|
||||
To enable this, pass `console: true` in the `development` object in `Bun.serve()`.
|
||||
|
||||
```ts
|
||||
import homepage from "./index.html";
|
||||
|
||||
Bun.serve({
|
||||
// development can also be an object.
|
||||
development: {
|
||||
// Enable Hot Module Reloading
|
||||
hmr: true,
|
||||
|
||||
// Echo console logs from the browser to the terminal
|
||||
console: true,
|
||||
},
|
||||
|
||||
routes: {
|
||||
"/": homepage,
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
When `console: true` is set, Bun will stream console logs from the browser to the terminal. This reuses the existing WebSocket connection from HMR to send the logs.
|
||||
|
||||
#### Production mode
|
||||
|
||||
|
||||
@@ -194,6 +194,18 @@ import "tailwindcss";
|
||||
|
||||
Only one of those are necessary, not all three.
|
||||
|
||||
## `--console` streams console logs from the browser to the terminal
|
||||
|
||||
Bun's dev server supports streaming console logs from the browser to the terminal.
|
||||
|
||||
To enable, pass the `--console` CLI flag.
|
||||
|
||||
{% bunDevServerTerminal alt="bun --console ./index.html" path="./index.html" routes="" /%}
|
||||
|
||||
Each call to `console.log` or `console.error` will be broadcast to the terminal that started the server.
|
||||
|
||||
Internally, this reuses the existing WebSocket connection from hot module reloading to send the logs.
|
||||
|
||||
## Keyboard Shortcuts
|
||||
|
||||
While the server is running:
|
||||
@@ -288,7 +300,6 @@ All paths are resolved relative to your HTML file, making it easy to organize yo
|
||||
|
||||
## This is a work in progress
|
||||
|
||||
- No HMR support yet
|
||||
- Need more plugins
|
||||
- Need more configuration options for things like asset handling
|
||||
- Need a way to configure CORS, headers, etc.
|
||||
|
||||
Reference in New Issue
Block a user