On this page
Configuration
ngp() takes one options object. The package from npm needs none of them, because it carries its own ngp build (Getting started). The table lists every option and what you get when you leave it out. Each name links to its own section: what the option does, when to change it, and an example where one helps.
Options#
| Option | Type, default | What it does |
|---|---|---|
toolchain | stringDefault: the NGP_TOOLCHAIN variable, then the ngp build inside the package | Compiles with another ngp build, one you made yourself |
engine | 'native' | 'wasm'Default 'native' | Picks the build of ngp's analyzer: the Node addon, or WebAssembly |
tsconfig | stringDefault tsconfig.app.json, else tsconfig.json | Names the tsconfig your Angular compiler options come from |
entries | string[]Default src/main.ts and the server entries that exist | Lists the modules the analyzer starts from |
entryOnlyTsconfig | booleanDefault true | Gives the analyzer a tsconfig that lists only entries, so edits stay fast |
hmr | booleanDefault true | Updates components in place in the dev server |
i18n | I18nOptionsOff by default | Builds one translated folder per locale |
ssr | boolean | SsrOptionsDefault false | Renders pages on the server, with or without @angular/ssr |
typeCheck | booleanDefault true, except under Vitest | Type-checks templates and TypeScript with TypeScript 7 |
typeChecker | 'tsgo' | 'tsrs'Default 'tsgo' | Picks which TypeScript 7 runs that check |
fileReplacements | {replace: string; with: string}[]Default [] | Swaps one source file for another, as angular.json does |
budgets | Budget[]Default [] | Checks angular.json's size budgets after vite build |
polyfills | string[]Default [] | Imports packages or files before your app, zone.js among them |
cache | boolean | {dir?: string}Default true | Reuses compiled output between builds and test runs |
workspaceRoot | stringDefault: the folder of your tsconfig | Starts paths in compiled code at the workspace root, so projects share it |
test | TestOptionsDefault: every switch off | Switches for specs, applied under Vitest only |
Here is the same list as code, every option at its default. Where a default depends on the project, the comment says how; the literal shown is what an app laid out like ng new's gets in the dev server and vite build:
import {defineConfig} from 'vite';
import {ngp} from '@push-based/vite-plugin-ngp';
export default defineConfig({
plugins: [
ngp({
toolchain: undefined, // NGP_TOOLCHAIN, else the ngp build inside the package
engine: 'native',
tsconfig: 'tsconfig.app.json', // else tsconfig.json; under Vitest, tsconfig.spec.json first
entries: ['src/main.ts'], // plus the server entries that exist (see entries); none under Vitest
entryOnlyTsconfig: true,
hmr: true,
i18n: undefined, // off
ssr: false,
typeCheck: true, // false under Vitest
typeChecker: 'tsgo',
fileReplacements: [],
budgets: [],
polyfills: [],
cache: true,
workspaceRoot: undefined, // the folder of your tsconfig
test: {}, // every switch off
}),
],
});If you have a vitest.config.ts as well, Vitest reads it instead of this file: see One config or two. Every type an option takes, such as SsrOptions, is exported from the package, as below.
toolchain#
- Type:
string - Default: the
NGP_TOOLCHAINvariable, then the ngp build inside the package
A directory holding another ngp build, preprocessor/ and engines/. Leave it unset: the package carries ngp for macOS (arm64 and x64) and Linux (x64 and arm64, glibc), and uses it when neither this nor the variable is set.
You need it only to run a build of ngp you made yourself, from a different Angular commit. A copy of the plugin that carries no ngp build, such as a clone of the repo, stops with no ngp build found until you set this or NGP_TOOLCHAIN.
engine#
- Type:
'native' | 'wasm' - Default:
'native'
Which build of ngp's analyzer to load: the native Node addon, or 'wasm'. There's no automatic fallback: on a platform the package has no native engine for, the plugin stops and says to set 'wasm'. Any other value, such as a misspelled 'natve', is an error at startup.
engine: 'wasm' is for platforms without a native build: Alpine and other musl-based Linux, Linux on a CPU other than x64 or arm64, and Windows outside WSL. It works everywhere, but the analyzer runs single-threaded. On a real app it took up to twice as long as native, which is why the plugin never switches to it on its own.
tsconfig#
- Type:
string - Default:
tsconfig.app.json, elsetsconfig.json. Under Vitest,tsconfig.spec.jsonfirst
The tsconfig your Angular compiler options come from, relative to Vite's root. When none of the default files exists and you don't name one, the plugin stops with no tsconfig found in ....
Name it when your app's tsconfig has another name. If Vitest reads the same config, set it only where it applies: tsconfig: 'tsconfig.app.json' hands specs a tsconfig that leaves them out (One config or two).
entries#
- Type:
string[] - Default:
src/main.ts,src/main.server.ts, thessr.entryyou name and, with@angular/ssr, thessr.serverfile,src/server.tsby default: each if it exists. Under Vitest, none
The modules the analyzer starts from, relative to Vite's root, and the ones polyfills and i18n are imported into. It finds every other file by following imports. Under Vitest it starts from each spec instead, when Vitest asks for it.
Set it when a module that nothing else imports needs compiling, such as a second entry point. A server entry with another name is already in the default when you name it in ssr: {entry: ...}, and so is your @angular/ssr server. Setting entries replaces the default entirely, existence check included, so list src/main.ts and your server entry too:
ngp({entries: ['src/main.ts', 'src/server.ts', 'src/admin.ts']});Files no entry reaches, directly or through imports, are invisible to the analyzer, and modules missing from entries don't get polyfills or the i18n prelude imported into them.
entryOnlyTsconfig#
- Type:
boolean - Default:
true
Give the analyzer a generated tsconfig that extends yours and lists only entries, so an edit doesn't get slower as the project grows. The plugin writes it to vite-plugin-ngp/tsconfig.entry.<hash>.json in Vite's cache directory.
entryOnlyTsconfig: false makes the analyzer read your tsconfig as it is. Use it if a file the analyzer should see isn't reachable from entries. Expect edits to get slower as the app grows: about 172 ms per edit at 5,000 components, against 1 ms.
hmr#
- Type:
boolean - Default:
true
Component HMR in the dev server, for external templates and for inline template and styles edits: the running component updates in place. Builds and Vitest ignore it. Component HMR says what updates in place and what reloads.
hmr: false makes every edit reload the page. Use it if an in-place update ever leaves a component in a broken state, and tell the maintainers at PushBased what you edited, so the rule that let it through can be fixed.
i18n#
- Type:
I18nOptions - Default: off
Angular i18n: i18n attributes and $localize. vite build writes one folder per locale, translated at build time, and the dev server serves devLocale.
Set it when your app has translated text. Leave it out while the app has a single language: without it, a $localize message needs @angular/localize/init imported by the app, as with the CLI. It doesn't work with @angular/ssr yet, so not in an app from the app-ssr template: the build stops with "i18n with @angular/ssr is not supported yet". A server entry that exports render(url, document) does work with it (Status).
Internationalization walks through marking, extracting and serving.
i18n.sourceLocale#
- Type:
string | {code: string; subPath?: string} - Default:
'en-US'
The language your templates are written in. It's built into a folder of its own, like every other locale, untranslated.
i18n.locales#
- Type:
Record<string, string | string[] | {translation: string | string[]; subPath?: string}> - Default: none
Each translated locale's code, and its translation file or files, relative to Vite's root. XLIFF 1.2 and 2.0, XMB/XTB, JSON and ARB are read, as with the Angular CLI. subPath, here and in sourceLocale, is the locale's output folder and URL segment, and defaults to its code:
ngp({
i18n: {
sourceLocale: 'en-US',
locales: {
de: 'src/locale/messages.de.xlf',
'fr-CA': {translation: 'src/locale/messages.fr-CA.xlf', subPath: 'fr'},
},
},
});i18n.devLocale#
- Type:
string - Default: the source locale
The locale the dev server serves.
i18n.missingTranslation#
- Type:
'error' | 'warning' | 'ignore' - Default:
'warning'
What to do with a message a translation file lacks.
ssr#
- Type:
boolean | SsrOptions - Default:
false
Server rendering. ssr: true is ssr: {}: every field below at its default. With @angular/ssr in your package.json, it renders the Angular CLI's way, with server as the Express server. Vitest ignores it. Server rendering has both ways to render, with and without @angular/ssr.
ssr: true renders every page on the server in the dev server, and makes vite build build two bundles below your build.outDir (dist by default): <outDir>/client for the browser and <outDir>/server/main.server.js for the server. With @angular/ssr in your package.json, the entry default-exports the bootstrap function, vite build also builds <outDir>/server/server.js from src/server.ts and prerenders, and the dev server hands requests to server.ts, as Server rendering describes. Without it, the entry's default export must be render(url, document).
ssr.entry#
- Type:
string - Default:
src/main.server.ts
The server entry, relative to Vite's root. It joins the default entries, so it gets zone.js/node and your other polyfills without being listed there. Name it when your server entry has another name: ssr: {entry: 'src/entry.server.ts'}.
ssr.server#
- Type:
string - Default:
src/server.ts, if it exists
With @angular/ssr only: the Node server, built into <outDir>/server/server.js. The dev server hands page requests to its reqHandler export. A path you name that doesn't exist stops the plugin; without the default file, vite build builds main.server.js alone, for a server you bring.
ssr.allowedHosts#
- Type:
string[] - Default:
['localhost']
With @angular/ssr only: the hosts the built server renders for, written into its manifest like angular.json's security.allowedHosts. Any other Host gets a 400. The dev server leaves the check to Vite's server.allowedHosts.
Set it to your production domains before you deploy; the list replaces the default. NG_ALLOWED_HOSTS, a comma-separated list, adds to it when the server starts.
typeCheck#
- Type:
boolean - Default:
true, except under Vitest
Type-check templates and TypeScript with TypeScript 7, in a separate process. The dev server reports errors in the terminal and the overlay after each edit, without holding up transforms or HMR, and vite build fails on them. See Type-checking.
typeCheck: false skips the check in the dev server and in builds. Use it if you already run tsc or ng build in CI and the dev-server check is too slow on your app, or if your cacheDir is outside the project. Builds then succeed with type errors in them. In the other direction, typeCheck: true in a config Vitest shares runs the check under Vitest too (One config or two).
typeChecker#
- Type:
'tsgo' | 'tsrs' - Default:
'tsgo'
Which TypeScript 7 runs the check: tsgo, Microsoft's Go port, which the plugin installs, or tsrs, Oxc's Rust port, which you install yourself.
typeChecker: 'tsrs' runs the same check with tsrs, a pre-1.0 Rust port of TypeScript 7, after npm install -D tsrs. On a 5,000-component app it reported a planted error in 1.02 s against tsgo's 1.36 s; on a small app there's nothing to gain. No package for Intel Macs. See Checking with tsrs.
fileReplacements#
- Type:
{replace: string; with: string}[] - Default:
[]
angular.json's fileReplacements, relative to Vite's root. Every import of replace gets the content of with, in Vite and in ngp's analyzer, in dev and in builds. A with file that doesn't exist stops the plugin with the Angular CLI's message.
It's for environment files. The plugin doesn't read Vite's mode, so pick the list by it yourself, the way angular.json picks it by configuration:
export default defineConfig(({mode}) => ({
plugins: [
ngp({
fileReplacements:
mode === 'production' ? [{replace: 'src/environments/environment.ts', with: 'src/environments/environment.prod.ts'}] : [],
}),
],
}));The replacement's relative imports resolve from the replaced file's directory, unlike under the CLI. Migrating from ng build explains why.
budgets#
- Type:
Budget[] - Default:
[]
angular.json's budgets: size limits checked after vite build, with the CLI's types and messages. An error budget fails the build. It takes angular.json's array as it is. These are the ones ng new generates:
ngp({
budgets: [
{type: 'initial', maximumWarning: '500kB', maximumError: '1MB'},
{type: 'anyComponentStyle', maximumWarning: '4kB', maximumError: '8kB'},
],
});Each entry is one of angular.json's budgets, with the same fields:
| Field | What it does |
|---|---|
type | What's measured. initial: what index.html loads before your app runs. all: every .js and .css file together. allScript: every .js file together. any: each file on its own. anyScript: each .js file on its own. anyComponentStyle: each component stylesheet. bundle: the chunk named name |
name | For bundle: the chunk's Rolldown name. Lazy chunks are named after their file; the chunk that holds src/main.ts also answers to main |
maximumWarning, maximumError | Warn, or fail the build, above this size |
minimumWarning, minimumError | Warn, or fail the build, below this size |
baseline | A size every other one is counted from: maximums are added to it, minimums subtracted. {baseline: '500kB', maximumError: '50kB'} fails above 550 kB |
warning, error | With baseline: warn, or fail, when the size is this far from the baseline in either direction |
A size is a number with b, kb, mb or gb, in any case, in powers of 1,000 as the CLI counts them: '500kB', '1MB'. A plain number is bytes, and '10%' is a share of baseline. Only the browser build is measured, after vite build. styleUrl files are measured as ng build measures them, minified. Inline styles are measured as written, so they come out larger. Budgets says where the sizes differ from ng build's.
polyfills#
- Type:
string[] - Default:
[]
angular.json's polyfills: packages or files imported before your app, at the top of each module in entries. zone.js also makes the plugin rewrite async/await so zone.js can track it.
It's only needed for apps that still run on zone.js, and for polyfill packages:
ngp({polyfills: ['zone.js']});On the server, zone.js becomes zone.js/node. A zoneless app, which is what ng new creates since Angular 21, leaves this empty. See Polyfills and zone.js.
cache#
- Type:
boolean | {dir?: string} - Default:
true
Keep compiled output between runs. vite build and Vitest then skip ngp's code generation, the linker and the build optimizer for every module whose inputs are unchanged. true keeps it in vite-plugin-ngp/cache under Vite's cacheDir, and {dir} in a directory you name. The dev server never uses it. See Reusing output between builds.
cache: false compiles every module on every build and test run, as the plugin did before 9 November 2026. Use it to rule the cache out when a build's output looks stale, and open an issue if that fixes it: a stale hit means the key is missing an input, which is a bug. Deleting node_modules/.vite/vite-plugin-ngp/cache has the same effect once. In CI, the cache only helps if its directory is restored between runs, with the project at the same path: every key holds its module's absolute path.
cache.dir#
- Type:
string - Default:
vite-plugin-ngp/cachein Vite'scacheDir, a different one for every Vitest project
The output cache's directory, absolute or relative to Vite's root. It's for a workspace with many Vitest projects. Vitest gives every project its own cacheDir, so by default each project links every Angular library for itself. With one directory for all of them, a library is linked once and the other projects read it. Build the path from the workspace root, because a relative one resolves from each project's own root and gives each its own directory again:
ngp({cache: {dir: path.join(workspaceRoot, 'node_modules/.cache/vite-plugin-ngp')}})Give the cache a folder of its own. The plugin refuses a dir that is Vite's root or a folder the root is in, such as the workspace root itself, because the entries would land among your sources.
On its own this shares library code only. Your own compiled modules stay per project, because ngp writes paths from the folder of each project's tsconfig into them. workspaceRoot is what lets projects share those too. And the linking alone saves less than it sounds: about a tenth of a second for a project Vitest has never run, in the one case measured. Sharing one directory between projects has the numbers and what the option leaves on the table.
workspaceRoot#
- Type:
string - Default: the folder of your tsconfig
The root of the workspace this project is one of, absolute or relative to Vite's root. It's for the same workspace as cache.dir, and goes next to it. By default ngp writes a class's file into its debug info, and a component's file into its HMR id, as a path from the folder that holds the project's tsconfig. A library file that two projects import then compiles to different code in each, so each compiles it for itself. With workspaceRoot those paths start at the workspace root, in every project:
ngp({
workspaceRoot,
cache: {dir: path.join(workspaceRoot, 'node_modules/.cache/vite-plugin-ngp')},
})Two projects then share a compiled module when their compiler options are the same, apart from where each tsconfig sits and where tsc would write. Template checks count as options: a project with strictTemplates and one without don't share, because an entry holds the module's diagnostics too. Set it in every project of the workspace or in none, since it changes the paths in the code. It has no effect on a project that stands alone, beyond those paths. See Sharing one directory between projects.
test#
- Type:
TestOptions - Default: every switch off
Switches for specs written for TestBed under JIT, and for workspaces with many Vitest projects. Every switch applies under Vitest only, and is off by default, so the option can sit in a Vite config your builds share. Without them, specs compile exactly like the app.
test.jitCompat#
- Type:
boolean - Default: off
Specs see what JIT TestBed saw. Libraries are linked for JIT and ngJitMode is true, so NgModules keep their scopes and TestBed.overrideComponent, overrideModule and overrideTemplate work on components that import one. @defer dependencies stay static imports, so class metadata is set without compileComponents(), and ng-mocks' MockComponent() works with such components. See Specs written for JIT.
test.runtimeScopes#
- Type:
boolean - Default: off
Drop the template scope errors TestBed resolves at runtime: NG8001 to NG8004 (unknown element, property, reference and pipe) in non-standalone components and in components a spec file declares, and NG8008 (missing required input) in components a spec file declares. They're real errors elsewhere, so leave it off unless specs need it.
test.extendedDiagnostics#
- Type:
'warning' - Default: unset: each diagnostic keeps the category your tsconfig gives it
Report Angular's extended diagnostics (NG81xx, NG8011 and NG8021) as warnings in specs, whatever category your tsconfig gives them. A check the tsconfig suppresses stays suppressed. Builds and the dev server still report them as configured. Any other value stops the plugin.
test.externalLibraries#
- Type:
boolean - Default: off
Leave Angular's libraries to Node and link each as it loads, from the output cache, so Vitest doesn't transform them once per project. Browser mode ignores it.
It's the third option for a workspace with many Vitest projects, after cache.dir and workspaceRoot, and the one that saves the most. Vitest transforms every inlined Angular library once per project, after the plugin, so no cache of the plugin's can serve it. With this switch the libraries stay with Node and are linked as they load, from the output cache. On the plugin's fixture a project Vitest has never run then takes 0.34–0.39 s, against 1.05–1.13 s. vi.mock then reaches a library only where your own code imports it, and the pool has to be forks or threads: Libraries left to Node has both, and the numbers.
One config or two#
When a project has both a vite.config.ts and a vitest.config.ts, Vitest reads only vitest.config.ts. Apps from create-ngp, and the setup on Testing with Vitest, have both files, each with its own ngp(). So an option you add to vite.config.ts doesn't reach your specs. On an app from create-ngp 0.4.3, with fileReplacements set in vite.config.ts only, a spec that imported the replaced file got the original under Vitest 5.0.4: expected 'original' to be 'replaced'.
To share the options, merge vite.config.ts into vitest.config.ts, and keep only Vitest's settings there:
import {defineConfig, mergeConfig} from 'vitest/config';
import viteConfig from './vite.config';
export default mergeConfig(
viteConfig,
defineConfig({
test: {
environment: 'node',
setupFiles: ['src/test-setup.ts'],
},
}),
);Don't call ngp() in this file too: the merged config already has the plugin, and a second call adds it twice. If vite.config.ts exports a function, as it does when you pick options by mode, call it: defineConfig((env) => mergeConfig(viteConfig(env), defineConfig({test: {...}}))).
The other way is one file: move the test block into vite.config.ts, add /// <reference types="vitest/config" /> at its top so TypeScript knows the block, and delete vitest.config.ts. Both ways made the spec above pass.
Sharing is safe for most options, because the plugin knows when it runs under Vitest:
- Ignored under Vitest:
ssr,hmrandbudgets. Keep them in the shared file. - Ignored outside Vitest:
test. It can sit in the shared file too. - Applied to both:
fileReplacements,engine,toolchain,cacheandworkspaceRoot, which is what you want. - A different default under Vitest:
tsconfig, where Vitest looks fortsconfig.spec.jsonfirst;entries, none; andtypeCheck, off. Setting one of these in the shared file sets it for specs too.tsconfig: 'tsconfig.app.json'hands specs a tsconfig that leaves them out, andtypeCheck: trueruns the type-check under Vitest too. Set them where they apply, or leave them out.
What the package exports#
import {
ngp,
extractMessages,
type NgpPluginOptions,
type SsrOptions,
type I18nOptions,
type TestOptions,
type Budget,
type ExtractOptions,
} from '@push-based/vite-plugin-ngp';| Export | What it is |
|---|---|
ngp(options?) | The plugin. It returns an array of Vite plugins, which goes in plugins as it is |
NgpPluginOptions | The options object. Type a config you share between files or projects with it |
SsrOptions, I18nOptions, TestOptions, Budget | The types of ssr, i18n, test and each of budgets |
extractMessages(options?) | What the ngp-extract-i18n command runs, for a script of your own. It resolves to {outFile, messages}: the file it wrote and how many messages are in it |
ExtractOptions | extractMessages's options, below |
A workspace whose projects share their cache settings can keep them in one typed file:
import * as path from 'node:path';
import {fileURLToPath} from 'node:url';
import type {NgpPluginOptions} from '@push-based/vite-plugin-ngp';
const workspaceRoot = path.dirname(fileURLToPath(import.meta.url));
export const shared: NgpPluginOptions = {
workspaceRoot,
cache: {dir: path.join(workspaceRoot, 'node_modules/.cache/vite-plugin-ngp')},
};extractMessages takes the command's options as an object:
| Field | Default | What it does |
|---|---|---|
root | The current directory | The Vite project root |
configFile | Vite's own lookup in root | The Vite config to build with |
format | 'xlf' | 'xlf' (XLIFF 1.2), 'xlf2', 'xmb', 'json' or 'arb' |
outFile | src/locale/messages.<extension> | Where to write, relative to root |
duplicates | 'warning' | 'error', 'warning' or 'ignore', for two messages with one id and different text |
import {extractMessages} from '@push-based/vite-plugin-ngp';
const {outFile, messages} = await extractMessages({format: 'xlf2'});
console.log(`${messages} messages in ${outFile}`);Environment variables#
| Variable | Read by | What it does |
|---|---|---|
NGP_TOOLCHAIN | The plugin | A directory holding an ngp build, used when the toolchain option isn't set, ahead of the build inside the package |
DEBUG | The plugin | DEBUG=vite-plugin-ngp, alone or in a comma-separated list, logs every module ngp compiles and each template update's timings to stderr. See below |
NG_ALLOWED_HOSTS | The server @angular/ssr builds, when it starts | A comma-separated list of hosts, added to ssr.allowedHosts |
VITEST | The plugin | Vitest sets it in its own process and every worker, and the plugin takes it to mean it runs under Vitest: no HMR, no ssr, the test switches on, and the different defaults. Don't set it yourself |
NGP_I18N_EXTRACT is the plugin's own: extractMessages sets it while it builds, so the build keeps every message untranslated. Don't set it either.
Vite settings the plugin reads#
The plugin takes these from your Vite config. None of them needs a value for the plugin's sake.
| Setting | What the plugin does with it |
|---|---|
root | Resolves every relative path in its options from it, and looks for your tsconfig there |
cacheDir | Keeps three things below vite-plugin-ngp/ in it: the output cache, the tsconfig the analyzer reads, and the type-check's tsconfig and build info. TypeScript resolves the check's types entries, such as vite/client, from there, so a cacheDir outside your project breaks the check for an app that lists types |
command | serve gets HMR and stylesheets as <link>s. build gets the output cache, the budgets and the inlined styles. Vitest counts as serve, with the cache on, and HMR and <link>s off |
build.outDir | With ssr, the parent of client/ and server/. With i18n, the parent of one folder per locale, below each of those |
environments.client.build.outDir, environments.ssr.build.outDir | Win over the folders the plugin picks, when you set them |
base | With @angular/ssr, the app's base href in the server's manifest. With i18n, the plugin sets it to './' for vite build and vite preview |
server.hmr | false, or {overlay: false}, keeps type errors out of the browser's overlay: the plugin leaves its overlay script out of index.html |
server.allowedHosts | With @angular/ssr, the dev server's Host check. ssr.allowedHosts only goes into the build |
The plugin doesn't read mode. Pick options by it yourself, as fileReplacements does.
When the plugin stops#
When an option can't work, the plugin stops Vite as it starts, or as the build starts, with a message that names what to fix and links its entry on Troubleshooting, which also covers the warnings and errors you meet later.
What the plugin sets for you#
You don't configure these, but they explain what you see when you debug:
define:ngJitMode,ngDevMode,ngServerMode,ngHmrModeandngI18nClosureMode, as How it works lists.optimizeDeps.rolldownOptions.plugins: Angular's linker, for the browser's dependency pre-bundling.- With
ssr, in the dev server:optimizeDepsfor thessrenvironment, with discovery on, so the server's Angular libraries are pre-bundled and linked once intonode_modules/.vite/deps_ssr. Its Rolldown plugins keep everything that isn't an Angular library out of the bundle, bake the server'sdefinevalues in, and delete the bundle's source maps. With@angular/ssr,optimizeDeps.entriesis your server entry andoptimizeDeps.includelists@angular/ssrand@angular/ssr/node. See Server rendering. - In the dev server, every other server environment, such as the Worker environment
@cloudflare/vite-pluginadds: Angular's linker in that environment'soptimizeDeps.rolldownOptions.plugins, next to the plugins its owner sets. The rest of its optimizer stays as its owner configured it. build.rolldownOptions.treeshake.manualPureFunctions:forwardRef, so unusedforwardRef(...)calls can be dropped, asng builddoes. The rest of the build optimizer is a transform and needs no configuration.resolve.noExternalin server environments: every@angular/*package, plus every package in yourdependenciesthat depends on@angular/core, so Angular libraries get bundled and linked instead of loaded unlinked by Node. An Angular library underdevDependenciesstays external; add it toresolve.noExternalyourself. With@angular/ssr, also everything@angular/ssrdepends on: beasties and its dependencies.- A dev-server middleware that answers
/@ng/componentrequests with component updates. - With
entryOnlyTsconfig: the generated tsconfig the analyzer reads,vite-plugin-ngp/tsconfig.entry.<hash>.jsonin Vite's cache directory. It extends yours and lists onlyentries. - With
typeCheck: avite-plugin-ngp/type-checkfolder in Vite's cache directory, holding the type-check blocks, the check's tsconfig and its incremental build info. In the dev server, a script tag inindex.htmlloads/@ngp/type-check-client.js, which shows type errors in Vite's overlay. It's left out whenserver.hmr.overlayisfalse. - A resolver for component stylesheet names in the dev server, like
card.ngp-de07cd19.css, and a transform that scopes component stylesheets after Vite's CSS plugin has compiled them. See Component styles. - With
ssr:builder: {},build.outDirfor theclientenvironment as<outDir>/clientand for thessrenvironment as<outDir>/server, unless you set an environment's ownbuild.outDir, and a middleware that renders page requests through your server entry. With@angular/ssr, thessrenvironment's input is two generated modules,main.serverandserver, that set@angular/ssr's manifests before your code runs, and awriteBundlehook writes the manifests and prerenders. Either way, the document the server renders into gets the script event replay needs, and with arenderentryvite buildwrites that document as<outDir>/server/index.server.html. - Under Vitest, where
ssr,hmrand the dev-server middleware don't apply:define:ngJitMode(truewithtest.jitCompat, elsefalse) andngHmrMode: false, andngServerModeby environment, as What the plugin does under Vitest describes. Vitest'snodeenvironment is a server environment, so it also getsresolve.noExternalas above, unlesstest.externalLibrariesis on.test.server.deps.inlinewith every Angular library, fromdevDependenciestoo, so they get linked.- With
test.externalLibraries, no inline list. Instead a setup file,vite-plugin-ngp/link-libraries.mjsin Vite's cache directory, goes first in each project'ssetupFilesand links libraries as Node loads them. Browser mode skips it. See Libraries left to Node. - Angular's linker in
optimizeDeps.rolldownOptions.plugins, for browser mode's pre-bundling. Withtest.jitCompatit links for JIT, andoptimizeDeps.rolldownOptions.transform.definesetsngJitMode: 'true'so a pre-bundle linked one way isn't reused for the other. - A cache key generator that keeps your app's modules out of Vitest's module cache, and a watcher that sends edits to the analyzer, since Vitest turns Vite's HMR off. See Testing with Vitest.
- With
fileReplacements: aloadhook that returns the replacement's content for the replaced file, and watches the replacement. - With
polyfills: one import per polyfill at the top of each module inentries. Withzone.js, atransformin the dev server and arenderChunkin builds that rewriteasyncfunctions with esbuild. - With
budgets: on the browser build, atransformthat measures each component stylesheet aftervite:css, and agenerateBundlehook that checks the sizes and logs the CLI's messages. - With
i18n: any@angular/localizeentry inpolyfillsis dropped. In the dev server:optimizeDeps.includewith@angular/localize, itsinitentry and the dev locale's data, for thessrenvironment too whenssris on, and an import added to the top of each entry module that sets up$localize. Invite buildandvite preview:base: './'andbuild.copyPublicDir: false, because the plugin writes every file below<outDir>/<locale>/itself, including the public directory.vite previewgets a middleware that serves each locale'sindex.htmland redirects/to a locale. See Internationalization.
To watch the plugin work, set DEBUG=vite-plugin-ngp. It logs every module ngp compiles, and how long each took, to stderr. For each template update it also logs how long each step took, from the watcher's report to sending the update:
vite-plugin-ngp hmr src/app/home.ts: watcher 111.8, read 0.1, analyze 0.6, owner 0.0, stat 0.1, wait 0.2, class 0.1, emit 3.3, transform 0.5, send 0.1 mswatcher is the time from the template's write to the watcher's report, stat reads the write's time, and wait is what was left of the 50 ms after it. See How it works.