@@ -191,10 +191,155 @@ After that, rebuilds are fast.
191191When you're ready to ship:
192192
193193``` sh
194- next-rust build # compiles and pre-renders what it can
194+ next-rust build # one small, self-contained binary in .next-rust/
195195next-rust start
196196```
197197
198+ ## Styling with Tailwind CSS
199+
200+ Tailwind CSS is built in. Write Tailwind classes in your views and the CSS is
201+ generated for exactly the classes you use. There's nothing to install and no
202+ CSS file to write: no Node.js, no npm, no ` tailwind.config.js ` .
203+
204+ ``` rust
205+ pub fn Page () -> impl View {
206+ main! [
207+ class (" mx-auto max-w-2xl px-6 py-24" ),
208+ h1! [class (" text-4xl font-bold tracking-tight dark:text-white" ), " Hello" ],
209+ a! [class (" btn mt-8" ), href (" /docs" ), " Read the docs" ],
210+ ]
211+ }
212+ ```
213+
214+ New projects use it from the start (` next-rust new my-app --no-tailwind `
215+ if you'd rather write plain CSS). In an existing project, turn it on in
216+ ` next-rust.toml ` :
217+
218+ ``` toml
219+ [tailwind ]
220+ enabled = true
221+ dark_mode = " media" # or "class" / "attribute"
222+ plugins = [" @tailwindcss/typography" ] # optional official plugins
223+
224+ [tailwind .theme ] # your design tokens
225+ color-brand = " #f26b2a" # → bg-brand, text-brand, ring-brand/50, …
226+ font-display = " Inter, sans-serif" # → font-display
227+
228+ [tailwind .utilities ] # your own classes
229+ btn = " inline-flex rounded-lg bg-brand px-4 py-2 font-semibold text-white hover:bg-brand/90"
230+ ```
231+
232+ How it works:
233+
234+ - The engine is the ** official Tailwind CSS v4.3.3** , so every class and
235+ variant in the [ Tailwind docs] ( https://tailwindcss.com/docs ) works.
236+ - The first time a Tailwind project builds, ` next-rust dev ` / ` next-rust build `
237+ download Tailwind's standalone engine for your system (with a progress bar),
238+ check it against the published SHA-256 checksum, and cache it for every
239+ project on the machine. It needs ` curl ` , which macOS, Windows 10+ and most
240+ Linux systems already have.
241+ - Only the classes found in ` app/ ` and ` src/ ` are generated. Development
242+ builds get readable CSS, release builds get it minified, and it's compiled
243+ into the binary, so servers need nothing extra.
244+ - Offline or locked-down CI? Download the executable yourself from the
245+ [ v4.3.3 release] ( https://github.com/tailwindlabs/tailwindcss/releases/tag/v4.3.3 )
246+ and set ` NEXT_RUST_TAILWIND_BIN=/path/to/tailwindcss ` .
247+
248+ Everything else (custom variants, safelisting classes built at runtime, raw
249+ keyframes) is on the Tailwind CSS page of the [ documentation] ( #documentation ) .
250+
251+ ## Deploying
252+
253+ ` next-rust build ` produces a single file, ` .next-rust/my-app ` , that contains
254+ your whole app: server, pages, ` next-rust.toml ` and everything in ` public/ ` .
255+ There are two common ways to ship it.
256+
257+ ### Copy the binary to a server
258+
259+ ``` sh
260+ next-rust build
261+ scp .next-rust/my-app you@your-server:/srv/my-app
262+ ssh you@your-server ' PORT=8080 /srv/my-app'
263+ ```
264+
265+ Nothing else needs to be installed on the server. Build on the same operating
266+ system and CPU architecture as the server (for example, a Linux x86-64 binary
267+ for a Linux x86-64 server). If you develop on a Mac and deploy to Linux, use
268+ Docker below: it builds the Linux binary for you.
269+
270+ ### Run it with Docker
271+
272+ You need [ Docker] ( https://docs.docker.com/get-docker/ ) installed and running.
273+ All commands run inside your project folder.
274+
275+ ** 1. Create the Dockerfile**
276+
277+ ``` sh
278+ next-rust docker
279+ ```
280+
281+ This writes two files:
282+
283+ - ` Dockerfile ` builds your app in the official Rust image, then copies only
284+ the finished binary into a minimal image
285+ (` gcr.io/distroless/cc-debian12:nonroot ` ) that runs as a non-root user.
286+ - ` .dockerignore ` keeps ` target/ ` , ` .next-rust/ ` , ` .git ` and local ` .env `
287+ files out of the build.
288+
289+ If a ` Dockerfile ` already exists, the command stops instead of overwriting it.
290+ Use ` next-rust docker --force ` to replace it.
291+
292+ ** 2. Build the image**
293+
294+ ``` sh
295+ docker build -t my-app .
296+ ```
297+
298+ The first build downloads and compiles every dependency, so it takes a few
299+ minutes. Later builds reuse the Cargo cache and are much faster.
300+
301+ ** 3. Run the container**
302+
303+ ``` sh
304+ docker run -p 3000:3000 my-app
305+ ```
306+
307+ Open http://localhost:3000 . Press Ctrl+C to stop it; the server finishes the
308+ requests it's handling before it exits.
309+
310+ ** Everyday commands**
311+
312+ | What you want | Command |
313+ | ---| ---|
314+ | Run in the background and restart after crashes or reboots | ` docker run -d --name my-app --restart unless-stopped -p 3000:3000 my-app ` |
315+ | See the logs | ` docker logs -f my-app ` |
316+ | Stop it | ` docker stop my-app ` |
317+ | Remove the stopped container | ` docker rm my-app ` |
318+ | Use another port | ` docker run -p 8080:8080 -e PORT=8080 my-app ` |
319+ | Pass secrets and settings | ` docker run -p 3000:3000 -e DATABASE_URL=... -e API_KEY=... my-app ` |
320+ | Pass them from a file | ` docker run -p 3000:3000 --env-file .env.production my-app ` |
321+
322+ ** Good to know**
323+
324+ - ** Rebuild after every change.** Your pages, config and ` public/ ` files are
325+ compiled into the image. After editing code, run ` docker build ` again, then
326+ replace the running container.
327+ - ** ` .env ` files are not in the image.** Pass secrets with ` -e ` or
328+ ` --env-file ` when you start the container, never bake them into the image.
329+ - ** Quiet by default.** A server running in the background prints only errors.
330+ Run with ` docker run -it ... ` to see the Next Rust startup screen.
331+ - ** ` -p host:container ` .** The left port is the one you open in the browser;
332+ the right one must match ` PORT ` inside the container (3000 unless you change
333+ it).
334+ - ** Small images.** The image holds one size-optimized binary (about 1–2 MB
335+ for a typical app) on top of the minimal base image. There is no Rust
336+ toolchain, shell or package manager in it.
337+ - ** Already have a Dockerfile from an older version?** Run
338+ ` next-rust docker --force ` to get the current one.
339+
340+ More options (Kubernetes, reverse proxies, TLS, platforms like Fly.io and
341+ Railway) are on the Deployment page of the [ documentation] ( #documentation ) .
342+
198343## Staying up to date
199344
200345New projects follow this GitHub repository, so updating is one command. Run
256401- ** Backend:** API routes, middleware at any level of the tree, cookies,
257402 sessions, CORS, rate limiting, server-sent events and WebSockets.
258403- ** Frontend:** HTML is escaped unless you explicitly ask for raw output.
259- CSS modules are scoped at compile time. Pages ship zero JavaScript unless
404+ Tailwind CSS v4 is built in (no Node.js), and CSS modules are scoped at
405+ compile time. Pages ship zero JavaScript unless
260406 they use client navigation or an interactive island, and even then it's a
261407 single ~ 4 KB script. Navigating between pages that share layouts renders
262408 and sends only the part below them; the layouts stay on screen.
0 commit comments