Experimental Rust compiler
Type: boolean
Default: false
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:
import { defineConfig } from "astro/config";
export default defineConfig({ experimental: { rustCompiler: true }});and then install the @astrojs/compiler-rs package into your project:
npm install @astrojs/compiler-rspnpm add @astrojs/compiler-rsyarn add @astrojs/compiler-rsExpected differences
Section titled “Expected differences”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 thedivfrom of thep)<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.
Limitations
Section titled “Limitations”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.