mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 19:13:34 +08:00
The Angular CLI will now enable the Node.js compile cache when available for use. Node.js v22.8 and higher currently provide support for this feature. The compile cache stores the v8 intermediate forms of JavaScript code for the Angular CLI itself. This provides a speed up to initialization on subsequent uses the Angular CLI. The Node.js cache is stored in a temporary directory in a globally accessible location so that all Node.js instances of a compatible version can share the cache. The code cache can be disabled if preferred via `NODE_DISABLE_COMPILE_CACHE=1`. Based on initial profiling, this change provides an ~6% production build time improvement for a newly generated project once the cache is available. ``` Benchmark 1: NODE_DISABLE_COMPILE_CACHE=1 node ./node_modules/.bin/ng build Time (mean ± σ): 2.617 s ± 0.016 s [User: 3.795 s, System: 1.284 s] Range (min … max): 2.597 s … 2.640 s 10 runs Benchmark 2: node ./node_modules/.bin/ng build Time (mean ± σ): 2.475 s ± 0.017 s [User: 3.555 s, System: 1.354 s] Range (min … max): 2.454 s … 2.510 s 10 runs Summary node ./node_modules/.bin/ng build ran 1.06 ± 0.01 times faster than NODE_DISABLE_COMPILE_CACHE=1 node ./node_modules/.bin/ng build ```
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
/**
|
|
* @fileoverview
|
|
*
|
|
* This file is used to bootstrap the CLI process by dynamically importing the main initialization code.
|
|
* This is done to allow the main bin file (`ng`) to remain CommonJS so that older versions of Node.js
|
|
* can be checked and validated prior to the execution of the CLI. This separate bootstrap file is
|
|
* needed to allow the use of a dynamic import expression without crashing older versions of Node.js that
|
|
* do not support dynamic import expressions and would otherwise throw a syntax error. This bootstrap file
|
|
* is required from the main bin file only after the Node.js version is determined to be in the supported
|
|
* range.
|
|
*/
|
|
|
|
// Enable on-disk code caching if available (Node.js 22.8+)
|
|
// Skip if running inside Bazel via a RUNFILES environment variable check. The cache does not work
|
|
// well with Bazel's hermeticity requirements.
|
|
if (!process.env['RUNFILES']) {
|
|
try {
|
|
const { enableCompileCache } = require('node:module');
|
|
|
|
enableCompileCache?.();
|
|
} catch {}
|
|
}
|
|
|
|
// Initialize the Angular CLI
|
|
void import('../lib/init.js');
|