Zum Inhalt springen

Experimental Rust compiler

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Type: boolean
Default: false

Hinzugefügt in: astro@6.0.0 Beta

Enables using the new Rust-based compiler for Astro files. This compiler is faster, provides better error messages, and generally has better support for modern JavaScript, TypeScript, and CSS features.

In a future major version, Astro will use this new compiler by default, but you can opt in to the future behavior early using the experimental.rustCompiler flag.

To give feedback on the compiler, or to keep up with its development, see the RFC for a new compiler for Astro for more information and discussion.

This experimental flag requires no specific usage and only affects which compiler Astro uses for your project.

To enable the Rust compiler, add the following to your astro.config.mjs:

astro.config.mjs
import { defineConfig } from "astro/config";
export default defineConfig({
experimental: {
rustCompiler: true
}
});

and then install the @astrojs/compiler-rs package into your project:

Terminal window
npm install @astrojs/compiler-rs

Unlike Astro’s current Go compiler, this experimental Rust compiler will not correct invalid HTML structure. For example, the following notable patterns will be left as written, and no longer corrected:

  • <p><div>Bad nesting</div></p> (instead of removing the div from of the p)
  • <p>My paragraph (instead of adding the missing closing </p> tag)

This means that if your Astro files contain invalid HTML, you may see a different output from the Rust compiler than you did with the previous compiler, or may encounter errors while building.

At this time, the Rust compiler does not support HTML minification (the compressHTML option in astro.config.mjs) and does not currently output the required metadata for the dev toolbar audits to work correctly.

Wirke mit Community Sponsor