diff --git a/packages/angular_devkit/build_angular/src/builders/browser/specs/lazy-module_spec.ts b/packages/angular_devkit/build_angular/src/builders/browser/specs/lazy-module_spec.ts index 016632feccb2..0631d4a610ec 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser/specs/lazy-module_spec.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser/specs/lazy-module_spec.ts @@ -152,7 +152,7 @@ describe('Browser Builder lazy modules', () => { const { files } = await browserBuild(architect, host, target); expect(files['src_one_ts.js']).not.toBeUndefined(); expect(files['src_two_ts.js']).not.toBeUndefined(); - expect(files['default-node_modules_angular_common_fesm2020_http_mjs.js']).toBeDefined(); + expect(files['default-node_modules_angular_common_fesm2015_http_mjs.js']).toBeDefined(); }); it(`supports disabling the common bundle`, async () => { @@ -165,6 +165,6 @@ describe('Browser Builder lazy modules', () => { const { files } = await browserBuild(architect, host, target, { commonChunk: false }); expect(files['src_one_ts.js']).not.toBeUndefined(); expect(files['src_two_ts.js']).not.toBeUndefined(); - expect(files['default-node_modules_angular_common_fesm2020_http_mjs.js']).toBeUndefined(); + expect(files['default-node_modules_angular_common_fesm2015_http_mjs.js']).toBeUndefined(); }); }); diff --git a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts index 43b386886c1f..3d24edec28e9 100644 --- a/packages/angular_devkit/build_angular/src/webpack/configs/common.ts +++ b/packages/angular_devkit/build_angular/src/webpack/configs/common.ts @@ -38,6 +38,7 @@ import { externalizePackages, getCacheSettings, getInstrumentationExcludedPaths, + getMainFieldsAndConditionNames, getOutputHashFormat, getStatsOptions, globalScriptsByBundleName, @@ -45,7 +46,16 @@ import { // eslint-disable-next-line max-lines-per-function export async function getCommonConfig(wco: WebpackConfigOptions): Promise { - const { root, projectRoot, buildOptions, tsConfig, projectName, sourceRoot, tsConfigPath } = wco; + const { + root, + projectRoot, + buildOptions, + tsConfig, + projectName, + sourceRoot, + tsConfigPath, + scriptTarget, + } = wco; const { cache, codeCoverage, @@ -266,7 +276,7 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise { + const mainFields = platformServer + ? ['es2015', 'module', 'main'] + : ['es2015', 'browser', 'module', 'main']; + const conditionNames = ['es2015', '...']; + + if (target >= ScriptTarget.ES2020) { + mainFields.unshift('es2020'); + conditionNames.unshift('es2020'); + } + + return { + mainFields, + conditionNames, + }; +}