On this page
Getting started
This page takes you from an Angular app to the same app served by Vite through vite-plugin-ngp. Plan on about five minutes. Your app needs to be on Angular 22.3.
What you need#
| Operating system | macOS (arm64 or x64) or Linux with glibc (x64 or arm64), WSL 2 included. Other Linux, Alpine included, needs engine: 'wasm' (Configuration). Windows itself doesn't work yet, not even with engine: 'wasm': use WSL 2 (Status) |
| Node | 26 |
| Package manager | npm, pnpm, bun, or Yarn with nodeLinker: node-modules. Yarn's default, Plug'n'Play, isn't supported |
| Angular | 22.3: 22.3.0-rc.0 or later, below 22.4.0. Compatibility has the range for each plugin version and how it was checked |
You don't need Rust or a clone of the repo. Angular hasn't published ngp, so the package carries its own build of it, made from Angular's source at the commit behind 22.3.2, with a native engine for each platform above.
1. Install the plugin#
npm install -D @push-based/vite-plugin-ngp vite@8.3.4With pnpm, pnpm add -D takes the same two packages.
Keep every @angular/* package on the same 22.3 release. An older Angular fails when ngp loads, because ngp imports names @angular/compiler first exported in 22.3.0-rc.0.
{
"dependencies": {
"@angular/common": "~22.3.0",
"@angular/compiler": "~22.3.0",
"@angular/core": "~22.3.0",
"@angular/platform-browser": "~22.3.0",
"@angular/router": "~22.3.0"
},
"devDependencies": {
"@angular/compiler-cli": "~22.3.0",
"typescript": "6.0.3"
}
}2. Add the plugin to Vite#
import {defineConfig} from 'vite';
import {ngp} from '@push-based/vite-plugin-ngp';
export default defineConfig({
plugins: [ngp()],
});ngp() needs no options. It loads the ngp build inside the package. Configuration lists what you can change.
3. Point Vite at your app#
Vite starts from index.html, not from angular.json. Put one in your project root that loads src/main.ts:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>My app</title>
<link rel="stylesheet" href="/src/styles.css" />
</head>
<body>
<app-root></app-root>
<script type="module" src="/src/main.ts"></script>
</body>
</html>The <link> brings in your global stylesheet, which angular.json listed under styles. Point it at your file, .scss included once sass is installed, or import the file from main.ts instead (Migrating from ng build).
Keep main.ts as ng new wrote it:
import {bootstrapApplication} from '@angular/platform-browser';
import {App} from './app/app';
import {appConfig} from './app/app.config';
bootstrapApplication(App, appConfig).catch((err) => console.error(err));The plugin reads tsconfig.app.json, or tsconfig.json if that doesn't exist, for your Angular compiler options. Then run:
npx viteFor a production build, run npx vite build. With pnpm, pnpm vite and pnpm vite build do the same. The output in dist/ is a static site you can serve from any file host.
Next#
- Migrating from ng build is your next page if you're moving an existing app: where each angular.json option goes,
ng serveand the scripts, and the fixes some sources need before they load. - Creating an app describes what
npm create @push-based/ngpwrites, if you'd rather compare with a fresh app. - How it works explains what happens between Vite's request and the compiled module.
- Configuration lists every option.
- Status and limits says what doesn't work yet. Read it before you try a large app.