github nitrojs/nitro v3.0.261103-rc

3 hours ago

๐Ÿ“ฆ New builders: Bun, Rspack and Rsbuild

In addition to Rolldown, Rollup and Vite, Nitro can now build your server with three new experimental builders:

Builder Use it with
Bun (#4987) bun --bun nitro build (selected automatically on Bun when rolldown/vite are not installed)
Rspack (#4942) builder: "rspack" or NITRO_BUILDER=rspack
Rsbuild (#5011) the nitro() plugin from nitro/rsbuild in rsbuild.config.ts

All builders run the same Rollup-compatible plugins: Nitro's own, your buildPlugins and the ones presets add. So all Nitro features and deployment presets work with each builder.

โšก Bun builder

bun --bun nitro build

The Bun builder bundles with Bun.build. It works with any preset (not only bun) and with nitro dev. Pass extra options with the new bunConfig option.

๐Ÿฆ€ Rspack builder

export default defineConfig({ builder: "rspack" });

The Rspack builder bundles the server with Rspack v2.3+. Like rolldown and vite, @rspack/core is installed on demand. It is not a dependency of Nitro. Load and transform filters become native Rspack loader conditions, so less work goes through JS. There is also a new rspack template for nitro create.

๐Ÿงฉ nitro/rsbuild plugin

import { defineConfig } from "@rsbuild/core";
import { nitro } from "nitro/rsbuild";

export default defineConfig({
  plugins: [nitro()],
});

This plugin works like nitro/vite, using the environments API of Rsbuild. Client, SSR and the Nitro server compile in one Rsbuild compiler. rsbuild dev, build, build --watch and preview work with Nitro, as do SSR outlets in the HTML template, ?assets imports and services. It also works with environments from other plugins, for example TanStack Start (@tanstack/react-start/plugin/rsbuild). ๐Ÿ‘‰ Rsbuild docs ยท examples: rsbuild-ssr-html, rsbuild-ssr-react, rsbuild-ssr-tss-react

Note

These builders are experimental: their behavior may change in minor releases. Known limits are listed in each PR. For example, emitFile only supports assets, and with Bun, library chunks are not grouped.

๐Ÿ”Œ Shared services + fetchService() (#5023)

Services are now part of Nitro core, with the same config and runtime API for nitro/vite and nitro/rsbuild:

export default defineConfig({
  services: { api: { entry: "./src/api-entry.ts" } },
});
import { fetchService } from "nitro/services";

const res = await fetchService("api", "/hello");

An ssr service is detected from an entry-server file. Your HTML template can render <!--ssr-outlet--> and use fetchService in its context. vite.services and fetchViteEnv() keep working as deprecated aliases.

๐Ÿงฑ Renderer templates compiled at build time (#5019)

The renderer template is now compiled at build time, in dev and production, with all builders. Templates are no longer evaluated at runtime (new Function), so template syntax works in dev on workerd/Cloudflare too (#5014). Syntax errors name the template file. With Vite dev, page requests no longer wait for transformIndexHtml (~306 ms โ†’ ~3 ms per page request in a benchmark with a slow HTML plugin). This release also fixes fetchViteEnv is not defined during prerendering.

โšก Vite integration

  • Built-in ?assets imports (#5013): ?assets imports are now built into Nitro, based on the original work by Hiroshi Ogawa (@hi-ogawa). nitro/rsbuild supports them too.
  • Vite base โ‡„ Nitro baseURL (#5022): vite build --base /app/ now serves routes and assets under /app/. Without a Vite base, Nitro baseURL is used as the Vite base. A baseURL set explicitly in Nitro config always wins.
  • Missing hashed assets return a no-store 404 (#5020): A request for an old chunk during a deploy no longer gets the HTML page with an immutable one-year cache header.

Important

Behavior changes: Server routes under the client assetsDir (/assets/ by default) now return 404 in production builds. With only a Vite base set, dev now matches production. Set baseURL: "/" to keep the server at the root.


compare changes

๐Ÿš€ Enhancements

  • Experimental bun builder (#4987)
  • Experimental rspack builder (#4942)
  • Shared services in core with fetchService from nitro/services (#5023)
  • Experimental nitro/rsbuild plugin (#5011)

๐Ÿฉน Fixes

  • dev: Compile renderer template with workerd eval binding (#5014)
  • vite: Return no-store 404 for missing hashed client assets (#5020)
  • vite: Use vite base as nitro baseURL and vice versa (#5022)

๐Ÿ’… Refactors

  • vite: Built-in ?assets imports (#5013)
  • Compile renderer template at build time in core (#5019)

๐Ÿ“– Documentation

  • Remove nightly-only mentions (1d39bf2b)

Preset Changes

  • vercel: Run scheduled tasks with vercel schedules (experimental) (#4756)
  • vercel: Invoke path schedules with GET (#5010)

โค๏ธ Contributors

Don't miss a new nitro release

NewReleases is sending notifications on new releases.