refactor(@angular-devkit/build-angular): extract webpack configuratio… · angular/angular-cli@528b7f1 · GitHub
Skip to content

Commit 528b7f1

Browse files
alan-agius4clydin
authored andcommitted
refactor(@angular-devkit/build-angular): extract webpack configurations from browser builder
1 parent f90a832 commit 528b7f1

5 files changed

Lines changed: 68 additions & 57 deletions

File tree

packages/angular_devkit/build_angular/src/browser/index.ts

Lines changed: 2 additions & 40 deletions

packages/angular_devkit/build_angular/src/dev-server/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import * as ts from 'typescript';
2020
import * as url from 'url';
2121
import * as webpack from 'webpack';
2222
import * as webpackDevServer from 'webpack-dev-server';
23-
import { getAnalyticsConfig, getCompilerConfig } from '../browser';
2423
import { Schema as BrowserBuilderSchema, OutputHashing } from '../browser/schema';
2524
import { ExecutionTransformer } from '../transforms';
2625
import { BuildBrowserFeatures, normalizeOptimization } from '../utils';
@@ -38,11 +37,13 @@ import {
3837
getIndexOutputFile,
3938
} from '../utils/webpack-browser-config';
4039
import {
40+
getAnalyticsConfig,
4141
getBrowserConfig,
4242
getCommonConfig,
4343
getDevServerConfig,
4444
getStatsConfig,
4545
getStylesConfig,
46+
getTypeScriptConfig,
4647
getWorkerConfig,
4748
} from '../webpack/configs';
4849
import { IndexHtmlWebpackPlugin } from '../webpack/plugins/index-html-webpack-plugin';
@@ -219,7 +220,7 @@ export function serveWebpackBrowser(
219220
getStylesConfig(wco),
220221
getStatsConfig(wco),
221222
getAnalyticsConfig(wco, context),
222-
getCompilerConfig(wco),
223+
getTypeScriptConfig(wco),
223224
browserOptions.webWorkerTsConfig ? getWorkerConfig(wco) : {},
224225
],
225226
devServerOptions,
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import { BuilderContext } from '@angular-devkit/architect';
10+
import { Configuration } from 'webpack';
11+
import { WebpackConfigOptions } from '../../utils/build-options';
12+
import { NgBuildAnalyticsPlugin } from '../plugins/analytics';
13+
14+
export function getAnalyticsConfig(
15+
wco: WebpackConfigOptions,
16+
context: BuilderContext,
17+
): Configuration {
18+
if (!context.analytics) {
19+
return {};
20+
}
21+
22+
// If there's analytics, add our plugin. Otherwise no need to slow down the build.
23+
let category = 'build';
24+
if (context.builder) {
25+
// We already vetted that this is a "safe" package, otherwise the analytics would be noop.
26+
category = context.builder.builderName.split(':')[1] || context.builder.builderName || 'build';
27+
}
28+
29+
// The category is the builder name if it's an angular builder.
30+
return {
31+
plugins: [
32+
new NgBuildAnalyticsPlugin(
33+
wco.projectRoot,
34+
context.analytics,
35+
category,
36+
!!wco.tsConfig.options.enableIvy,
37+
),
38+
],
39+
};
40+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
export * from './analytics';
910
export * from './browser';
1011
export * from './common';
1112
export * from './dev-server';

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

Lines changed: 22 additions & 15 deletions

0 commit comments

Comments
 (0)