Astro 6.2

By
Emanuele Stoppa
Matthew Phillips

Astro 6.2 is here! This release brings an experimental custom logger with built-in JSON output, perfect for structured logging and coding agents. It also includes a new SVG optimizer API, a font file URL helper, and more.

Explore what’s new in this release:

To upgrade an existing project, use the automated @astrojs/upgrade CLI tool. Alternatively, upgrade manually by running the upgrade command for your package manager:

# Recommended:
npx @astrojs/upgrade
# Manual:
npm install astro@latest
pnpm upgrade astro --latest
yarn upgrade astro --latest

SVG optimizer

Astro’s experimental SVG optimization has been redesigned with a new svgOptimizer option that replaces the previous svgo flag. Instead of being tied directly to SVGO, the new API introduces an SvgOptimizer interface that any optimization library can implement. Astro ships with a built-in svgoOptimizer() based on SVGO, but you can now swap in alternatives like OxVG.

astro.config.mjs
import { defineConfig, svgoOptimizer } from "astro/config";
export default defineConfig({
experimental: {
svgOptimizer: svgoOptimizer()
}
});

When enabled, all imported SVG files used as components are optimized at build time for smaller file sizes and better performance. You can pass a SVGO configuration object to customize the optimization:

astro.config.mjs
import { defineConfig, svgoOptimizer } from "astro/config";
export default defineConfig({
experimental: {
svgOptimizer: svgoOptimizer({
plugins: ["preset-default", { name: "removeViewBox" }]
})
}
});

If you were previously using experimental.svgo, update your config to use the new svgOptimizer option instead.

For more information, see the experimental SVG optimization docs.

Experimental Logger

It’s now possible to control the Astro logger with custom loggers. As part of the experimental feature, Astro ships with built-in loggers, such as a JSON logger. If you use coding agents to work with Astro, structured logs will definitely help your workflow.

JSON logger

You can enable JSON logging via configuration using experimental.logger, or via CLI using the flag --experimentalJson:

astro.config.mjs
import { defineConfig, logHandlers } from "astro/config";
export default defineConfig({
experimental: {
logger: logHandlers.json()
}
})
astro dev --experimentalJson
astro sync --experimentalJson
astro build --experimentalJson

Custom logger

You can also create your own custom logger by implementing the correct interface:

astro.config.mjs
import { defineConfig } from "astro/config";
export default defineConfig({
experimental: {
logger: {
entrypoint: "@org/custom-logger"
}
}
})
@org/custom-logger.ts
import type { AstroLoggerDestination, AstroLoggerMessage } from "astro";
import { matchesLevel } from "astro/logger";
function customLogger(level = 'info'): AstroLoggerDestination {
return {
write(message: AstroLoggerMessage) {
if (matchesLevel(message.level, level)) {
// write message somewhere
}
}
}
}
export default customLogger;

For more information on enabling and using this feature in your project, see the Experimental Logger docs.

For a complete overview and to give feedback on this experimental API, see the Custom logger RFC.

Experimental: getFontFileURL()

You can now load font file data during prerendering using the new experimental_getFontFileURL() helper exported from astro:assets. This makes it possible to use Astro-managed fonts with tools like Satori for generating Open Graph images at build time, something that previously required workarounds with undocumented internal paths.

src/pages/og.png.ts
import type { APIRoute } from "astro";
import { fontData, experimental_getFontFileURL } from "astro:assets";
import satori from "satori";
import { html } from "satori-html";
import sharp from "sharp";
export const GET: APIRoute = async (context) => {
const fontPath = fontData["--font-roboto"][0]?.src[0]?.url;
if (fontPath === undefined) {
throw new Error("Cannot find the font path.");
}
const url = experimental_getFontFileURL(fontPath, context.url);
const data = await fetch(url).then((res) => res.arrayBuffer());
const svg = await satori(
html`<div style="color: black;">hello, world</div>`,
{
width: 600,
height: 400,
fonts: [
{
name: "Roboto",
data,
weight: 400,
style: "normal",
},
],
},
);
const pngBuffer = await sharp(Buffer.from(svg))
.resize(600, 400)
.png()
.toBuffer();
return new Response(new Uint8Array(pngBuffer), {
headers: { "Content-Type": "image/png" },
});
};

For more information, see the Fonts API documentation.

Astro v7 alpha

Work on the next major version of Astro has begun. The first Astro 7 alpha includes two big changes:

Vite 8 support

Astro 7 upgrades to Vite 8, the latest major version of the build tool that powers Astro. This is a breaking change for Astro integrations and plugins that depend on Vite internals, but most Astro users should be able to upgrade without any changes to their project code.

Stable Rust compiler

The Rust-based Astro compiler, previously available as an experimental flag (experimental.rustCompiler), is now the default and only compiler in Astro 7. The Rust compiler delivers significantly faster build times compared to the previous Go-based compiler. The experimental.rustCompiler flag is no longer needed and can be removed from your config.

Try it out

The Astro 7 alpha is available for early testing:

npm install astro@alpha

We’d love to hear your feedback! Please report any issues you encounter on GitHub.

Other improvements

  • allowedHosts for preview servers: Astro’s server.allowedHosts option is now passed down to adapter preview servers, letting you control which hostnames are accepted when running astro preview behind a reverse proxy or with custom local domains. If you’re an adapter author, allowedHosts is now available on the options object passed to your preview entrypoint. See the adapter reference for details.
  • "jsx" option for compressHTML: The compressHTML option now accepts a "jsx" value that strips whitespace using JSX rules, so whitespace behaves the same way across .astro and .tsx files. Multi-line indented text is collapsed into a single line with spaces between words, while whitespace inside <pre> tags is preserved.

For a complete list of bug fixes and smaller improvements, see the full changelog.

Community

The Astro core team is:

Alexander Niebuhr , Armand Philippot , Chris Swithinbank , Emanuele Stoppa , Erika , Florian Lefebvre , Fred Schott , HiDeoo , Luiz Ferraz , Matt Kane , Matthew Phillips , Reuben Tier , Sarah Rainsberger , and Yan Thomas .

Thanks to all the other contributors who helped make Astro 6.2 possible with code and docs additions and improvements, including:

AitorMT, Alejandro Romano, Alex Dombroski, Amar Reddy, Andreas Deininger, Aral Roca Gomez, BitToby, Bobo Chen (陳柏宏), ChrisLaRocque, Ciaran Moran, Daniel Zamyatin, Daniil Sivak, dataCenter430, Desel72, Ed Melly, Eveeifyeve, Felix Schneider, Felmon, fkatsuhiro, hank00111, Invictus Navarchus, James Murty, James Opstad, John L. Armstrong IV, Johnny Noble, junetpoint, Junseong Park, kimulaco, ld-web, Leif Marcus, Louis Escher, Martin DONADIEU, Martin Trapp, Mathieu Mafille, Matthias, Max Malkin, Maxim Slobodchikov, meyer, Milo, Misrilal, moktamd, ocavue, Peter Philipp, Pierre G., Rafael Yasuhide Sudo, randomguy-2650, Rayan Salhab, Roman, Ronan Berder, saif-at-scalekit, Sakku 🦉, Sebastian Beltran, Sebastien Barre, Shinya Fujino, Thomas Bonnet, tmimmanuel, Tobias Breit, travisBREAKS, ubutatu, vrabe, Will (liruifengv), and もっちー