Skip to content

Commit 26dced9

Browse files
alan-agius4dgp1130
authored andcommitted
fix(@angular-devkit/build-angular): JIT support for standalone applications
This commit fixes and issue were standalone applications would fail during runtime because the `@angular/compiler` is not available. We now add the `@angular/compiler` as part of the bundle when JIT mode is enabled. (cherry picked from commit 2fabeab)
1 parent 7d792b2 commit 26dced9

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

packages/angular_devkit/build_angular/src/builders/browser-esbuild/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@ function createCodeBundleOptions(
327327
const {
328328
workspaceRoot,
329329
entryPoints,
330-
polyfills,
331330
optimizationOptions,
332331
sourcemapOptions,
333332
tsconfig,
@@ -412,6 +411,11 @@ function createCodeBundleOptions(
412411
},
413412
};
414413

414+
const polyfills = options.polyfills ? [...options.polyfills] : [];
415+
if (jit) {
416+
polyfills.push('@angular/compiler');
417+
}
418+
415419
if (polyfills?.length) {
416420
const namespace = 'angular:polyfills';
417421
buildOptions.entryPoints = {

packages/angular_devkit/build_angular/src/webpack/configs/common.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
5858
aot = true,
5959
codeCoverageExclude = [],
6060
main,
61-
polyfills,
6261
sourceMap: {
6362
styles: stylesSourceMap,
6463
scripts: scriptsSourceMap,
@@ -126,7 +125,12 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
126125
}
127126
}
128127

129-
if (polyfills?.length) {
128+
const polyfills = [...buildOptions.polyfills];
129+
if (!aot) {
130+
polyfills.push('@angular/compiler');
131+
}
132+
133+
if (polyfills.length) {
130134
// `zone.js/testing` is a **special** polyfill because when not imported in the main it fails with the below errors:
131135
// `Error: Expected to be running in 'ProxyZone', but it was not found.`
132136
// This was also the reason why previously it was imported in `test.ts` as the first module.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ng } from '../../utils/process';
2+
import { updateJsonFile, useCIChrome, useCIDefaults } from '../../utils/project';
3+
4+
export default async function () {
5+
await ng('generate', 'app', 'test-project-two', '--standalone', '--skip-install');
6+
7+
// Make prod use JIT.
8+
await updateJsonFile('angular.json', (configJson) => {
9+
const appArchitect = configJson.projects['test-project-two'].architect;
10+
const config = appArchitect.build.configurations;
11+
config['production'].aot = false;
12+
config['production'].buildOptimizer = false;
13+
config['development'].aot = false;
14+
});
15+
16+
// Setup testing to use CI Chrome.
17+
await useCIChrome('test-project-two', './e2e/');
18+
await useCIDefaults('test-project-two');
19+
20+
// Test it works
21+
await ng('e2e', '--configuration=production');
22+
await ng('e2e', '--configuration=development');
23+
}

0 commit comments

Comments
 (0)