On this page
Angular Compilation
The AnalogJS Vite Plugin (@analogjs/vite-plugin-angular) compiles your Angular components, directives, and pipes to Ivy definitions during the Vite build. It provides two compilation paths:
- Default compilation: Angular's own compiler (
ngtsc), with opt-in compile-time type checking. - Fast compile: an in-tree single-pass compiler that produces the same Ivy output much faster.
Both emit identical Ivy code and identical runtime behavior, because both ultimately call the same @angular/compiler lowering APIs.
Default compilation
This is what you get out of the box with no configuration required:
// vite.config.ts
import { defineConfig } from 'vite';
import angular from '@analogjs/vite-plugin-angular';
export default defineConfig({
plugins: [angular()],
});
The default path runs Angular's compiler (ngtsc) directly. By default it reports only syntax errors, because disableTypeChecking defaults to true. Set it to false to also report TypeScript and Angular template diagnostics, including strictTemplates errors, from the Vite build:
angular({
disableTypeChecking: false,
});
Library builds (build.lib) also emit declaration files.
Editing multiple files
During development, the default compilation path groups component and resource changes received within a 100 ms quiet window into one compilation. Reload and HMR notifications are coalesced after compilation, so saving several files at once avoids compiling separately for every file. Changes received during a compilation are queued for the next batch. This behavior requires no configuration.
Non-Angular TypeScript
Analog leaves .ts and .js files to the Angular compiler and turns Vite's own TypeScript transform off for them. Files outside the Angular program, such as a custom Node server loaded through Vite, are then not compiled. To have Vite compile them, set the transform in your own config. Analog keeps your setting instead of adding its exclusions, and files it doesn't include stay with the Angular compiler:
// vite.config.ts
import analog from '@analogjs/platform';
import angular from '@analogjs/vite-plugin-angular';
import { defineConfig } from 'vite';
export default defineConfig({
oxc: { include: [/\/src\/server\/.*\.ts$/] }, // `esbuild` on Vite 6 and 7
plugins: [analog(), angular()],
});
Fast compile
Fast compile swaps Angular's compiler for an in-tree, single-pass transform. Instead of constructing a full ts.Program, it extracts each file's decorator metadata and generates Ivy definitions directly through @angular/compiler's lowering APIs. It produces equivalent Ivy output and reduces cold-build and hot-rebuild times.
Enabling
Opt in via the angular() plugin:
// vite.config.ts
import { defineConfig } from 'vite';
import angular from '@analogjs/vite-plugin-angular';
export default defineConfig({
plugins: [
angular({
fastCompile: true,
}),
],
});
What it supports
| Capability | Fast compile |
|---|---|
AOT compilation (ɵɵdefineComponent) |
✅ |
| JIT compilation | ✅ |
Inline template: / styles: |
✅ Inline SCSS / Sass / Less is preprocessed before compilation |
External templateUrl / styleUrl |
✅ Resolved and preprocessed via Vite |
| Hot Module Replacement (HMR) | ✅ |
| Style encapsulation | ✅ |
| Cross-file selector resolution | ✅ Via an in-tree component registry |
Library / partial builds (fastCompileMode) |
✅ Emits partial declarations for library publishing |
| Compile-time template type checking | ❌ Use the Angular Language Service in your editor |
host keys/values from imported constants |
❌ Use a string literal, a same-file const, or @HostBinding |
Boundary blocks
Fast compilation supports @boundary and @error blocks when the installed
@angular/compiler supports them (verified with 22.2.0-next.7). Deferred
components inside error blocks are loaded lazily, while components also used
outside a @defer body remain eager dependencies. Older compilers, including
Angular 22.1, do not support this syntax.
Building a library
For a library build, set fastCompileMode: 'partial' so the compiler emits partial ɵɵngDeclare* declarations instead of final Ivy definitions:
angular({
fastCompile: true,
fastCompileMode: 'partial',
});
See Building an Angular library for the full library workflow.
NGP compilation (experimental)
The compilation option selects the Angular compiler implementation:
'ngtsc'(default): Angular's standard compiler.'ngp': Angular's experimental hybrid preprocessor, with in-memory TypeScript 7 and Angular template type checking enabled by default.
An explicit compilation takes precedence over fastCompile.
angular({
compilation: 'ngp',
jit: false,
});
Vitest defaults to JIT, so set jit: false explicitly to use NGP. Without it,
tests fall back to 'ngtsc'.
NGP is loaded only when selected. It resolves @angular/ngp from your
application and otherwise uses an interim NGP build bundled with
@analogjs/vite-plugin-angular, with a WebAssembly analyzer that runs on every
platform. The bundled build tracks an unreleased Angular revision and is replaced
by @angular/ngp once it is published. The bundled build requires Angular v22.2
or later.
NGP currently supports AOT application compilation and Vite preprocessing for
component styles. Set inlineStylesExtension for inline
SCSS/Sass/Less; external styles use their file extension. An explicit
jit: true and fastCompileMode: 'partial' are rejected.
TypeScript and Angular template type checking run in memory by default, without
emitting intermediate files, and report errors at their template location. They
require TypeScript 7; while Angular requires TypeScript 6, install the preview
alongside it, or set disableTypeChecking: true to skip type checking:
npm install -D @typescript/native-preview
Choosing a type checker
The typeChecker option selects the TypeScript 7 language server NGP type-checks with:
'tsgo'(default):typescript@^7or@typescript/native-preview. Set theTSNATIVE_BINARY_PATHenvironment variable to use a specific binary.'tsrs': tsrs, a Rust port of the TypeScript 7 checker. Install thetsrspackage.{ command, args }: any executable that serves the TypeScript 7 language server over stdio.argsdefaults to['--lsp', '--stdio'].
angular({
compilation: 'ngp',
jit: false,
typeChecker: 'tsrs',
});
Diagnostics follow the TypeScript version the checker implements, so switching checkers can surface errors your current version does not report.
Component HMR
NGP reloads the page on every change by default. Set liveReload: true to
update components in place instead:
angular({
compilation: 'ngp',
jit: false,
liveReload: true,
});
Components update in place after changes to their template and style files,
including files those styles import, and after edits to a component file that
only change its template, templateUrl, styles, styleUrl, or stylesUrl.
Any other change, or a change that fails to compile, reloads the page. With
HMR enabled, @defer dependencies load eagerly during development.
Type checking
Fast compile does not type-check your templates or TypeScript, and the default path only does so with disableTypeChecking: false. NGP type-checks by default; see NGP compilation. To catch those errors without slowing the build, run Angular's compiler as a separate verification step against your app's tsconfig. Pass --noEmit so it only reports errors without writing output:
ngc -p tsconfig.app.json --noEmit
Add it as a script and run it alongside your build:
// package.json
{
"scripts": {
"typecheck": "ngc -p tsconfig.app.json --noEmit"
}
}
This keeps fast builds during development while still failing on template and type errors before you ship, and the Angular Language Service surfaces the same errors live in your editor.
Nx workspaces
In an Nx workspace, angular-typechecker provides an Nx executor that runs the complete Angular type-check: TypeScript checks, template type-checking, and the extended NG8xxx diagnostics. It emits nothing and runs separately from your build and tests. Nx caches the result per project.
Add it with nx add, which installs the package and runs its angular-typechecker:init generator to seed a cacheable angular-typechecker:typecheck entry in nx.json under targetDefaults:
nx add angular-typechecker
Then wire a typecheck target into the project you want to check:
nx g angular-typechecker:configuration my-app
Run it:
nx typecheck my-app
The generator writes this target. Add includeDeps: true to also report diagnostics from dependencies:
// apps/my-app/project.json
{
"targets": {
"typecheck": {
"executor": "angular-typechecker:typecheck",
"options": {
"tsConfig": "apps/my-app/tsconfig.json",
"includeDeps": true,
},
},
},
}
Angular Compilation API (experimental)
angularCompilationPlugin() compiles through the Angular Compilation API from @angular/build, the same API the Angular CLI uses. It requires Angular v20.1 or later with a matching @angular/build package installed. Use it in place of angular():
// vite.config.ts
import { defineConfig } from 'vite';
import { angularCompilationPlugin } from '@analogjs/vite-plugin-angular';
export default defineConfig({
plugins: [angularCompilationPlugin()],
});
It accepts tsconfig, workspaceRoot, inlineStylesExtension, jit, liveReload, disableTypeChecking, fileReplacements, include, and debug, which behave as they do on angular(). Fast compile options are not supported.
Compatibility
Angular versions
Fast compile is validated against Angular 20, 21, latest, and next conformance fixtures on PRs that touch the compiler, and against the 20.0.0 and 21.0.0 compiler APIs on beta-targeted PRs that touch the compiler.
For overall Angular/Analog/Vite version support, see Version Compatibility.
Default vs fast compile
| Default | Fast compile | |
|---|---|---|
| Ivy output | Full | Identical |
| Cold build / hot rebuild | Standard | Significantly faster |
| Compile-time template type checking | Opt-in (disableTypeChecking: false) |
No (use the Angular Language Service) |
| Library / partial builds | Yes | Yes (fastCompileMode: 'partial') |