Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions packages/angular_devkit/build_angular/src/babel/webpack-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import { custom } from 'babel-loader';
import { ScriptTarget } from 'typescript';

interface AngularCustomOptions {
forceES5: boolean;
Expand Down Expand Up @@ -62,9 +63,11 @@ export default custom<AngularCustomOptions>(() => {
});

return {
async customOptions({ forceES5, ...loaderOptions }, { source }) {
let shouldProcess = forceES5;
async customOptions({ scriptTarget, ...loaderOptions }, { source }) {
// Must process file if plugins are added
let shouldProcess = Array.isArray(loaderOptions.plugins) && loaderOptions.plugins.length > 0;

// Analyze file for linking
let shouldLink = false;
const { hasLinkerSupport, requiresLinking } = await checkLinking(this.resourcePath, source);
if (requiresLinking && !hasLinkerSupport) {
Expand All @@ -77,17 +80,27 @@ export default custom<AngularCustomOptions>(() => {
}
shouldProcess ||= shouldLink;

// Analyze for ES target processing
let forceES5 = false;
const esTarget = scriptTarget as ScriptTarget;
if (esTarget < ScriptTarget.ES2015) {
forceES5 = true;
}
shouldProcess ||= forceES5;

// Add provided loader options to default base options
const options: Record<string, unknown> = {
...baseOptions,
...loaderOptions,
};

// Skip babel processing if no actions are needed
if (!shouldProcess) {
// Force the current file to be ignored
options.ignore = [() => true];
}

return { custom: { forceES5: !!forceES5, shouldLink }, loader: options };
return { custom: { forceES5, shouldLink }, loader: options };
},
config(configuration, { customOptions }) {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
I18NMissingTranslation,
IndexUnion,
Localize,
OptimizationClass,
SourceMapClass,
} from '../browser/schema';
import { Schema as DevServerSchema } from '../dev-server/schema';
Expand Down Expand Up @@ -98,5 +97,5 @@ export interface WebpackConfigOptions<T = BuildOptions> {
buildOptions: T;
tsConfig: ParsedConfiguration;
tsConfigPath: string;
supportES2015: boolean;
scriptTarget: import('typescript').ScriptTarget;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function generateWebpackConfig(
buildOptions,
tsConfig,
tsConfigPath,
supportES2015,
scriptTarget,
};

wco.buildOptions.progress = defaultProgress(wco.buildOptions.progress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
cacheIdentifier: JSON.stringify({
buildAngular: require('../../../package.json').version,
}),
forceES5: !wco.supportES2015,
scriptTarget: wco.scriptTarget,
},
},
...buildOptimizerUseRule,
Expand Down