Skip to content

Commit 6440869

Browse files
clydinfilipesilva
authored andcommitted
refactor(@angular/cli): remove unneeded production webpack config partial
1 parent 2a9dd7b commit 6440869

File tree

8 files changed

+35
-87
lines changed

8 files changed

+35
-87
lines changed

packages/@angular/cli/commands/build.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ export const baseBuildCommandOptions: any = [
158158
{
159159
name: 'extract-licenses',
160160
type: Boolean,
161-
default: true,
162161
description: 'Extract all licenses in a separate file, in the case of production builds only.'
163162
},
164163
{

packages/@angular/cli/models/webpack-config.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { BuildOptions } from './build-options';
99
import {
1010
getBrowserConfig,
1111
getCommonConfig,
12-
getProdConfig,
1312
getStylesConfig,
1413
getServerConfig,
1514
getNonAotConfig,
@@ -58,7 +57,6 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
5857
getCommonConfig(this.wco),
5958
platformConfig,
6059
getStylesConfig(this.wco),
61-
this.getTargetConfig(this.wco)
6260
];
6361

6462
if (this.wco.appConfig.main || this.wco.appConfig.polyfills) {
@@ -72,13 +70,6 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
7270
return this.config;
7371
}
7472

75-
public getTargetConfig(webpackConfigOptions: WebpackConfigOptions<T>): any {
76-
switch (webpackConfigOptions.buildOptions.target) {
77-
case 'production':
78-
return getProdConfig(webpackConfigOptions);
79-
}
80-
}
81-
8273
// Validate build options
8374
public validateBuildOptions(buildOptions: BuildOptions) {
8475
buildOptions.target = buildOptions.target || 'development';
@@ -110,7 +101,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
110101
sourcemaps: false,
111102
extractCss: true,
112103
namedChunks: false,
113-
aot: true
104+
aot: true,
105+
extractLicenses: true,
114106
}
115107
};
116108

packages/@angular/cli/models/webpack-configs/browser.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import * as webpack from 'webpack';
22
import * as path from 'path';
33
const HtmlWebpackPlugin = require('html-webpack-plugin');
44
const SubresourceIntegrityPlugin = require('webpack-subresource-integrity');
5-
5+
import { LicenseWebpackPlugin } from 'license-webpack-plugin';
66
import { generateEntryPoints, packageChunkSort } from '../../utilities/package-chunk-sort';
77
import { BaseHrefWebpackPlugin } from '../../lib/base-href-webpack';
88
import { IndexHtmlWebpackPlugin } from '../../plugins/index-html-webpack-plugin';
99
import { extraEntryParser, lazyChunksFilter } from './utils';
1010
import { WebpackConfigOptions } from '../webpack-config';
1111

12+
/**
13+
* license-webpack-plugin has a peer dependency on webpack-sources, list it in a comment to
14+
* let the dependency validator know it is used.
15+
*
16+
* require('webpack-sources')
17+
*/
1218

1319
export function getBrowserConfig(wco: WebpackConfigOptions) {
1420
const { projectRoot, buildOptions, appConfig } = wco;
@@ -68,6 +74,15 @@ export function getBrowserConfig(wco: WebpackConfigOptions) {
6874
}));
6975
}
7076

77+
if (buildOptions.extractLicenses) {
78+
extraPlugins.push(new LicenseWebpackPlugin({
79+
pattern: /^(MIT|ISC|BSD.*)$/,
80+
suppressErrors: true,
81+
perChunkOutput: false,
82+
outputFilename: `3rdpartylicenses.txt`
83+
}));
84+
}
85+
7186
const globalStylesEntries = extraEntryParser(appConfig.styles, appRoot, 'styles')
7287
.map(style => style.entry);
7388

packages/@angular/cli/models/webpack-configs/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { extraEntryParser, getOutputHashFormat, AssetPattern } from './utils';
55
import { isDirectory } from '../../utilities/is-directory';
66
import { requireProjectModule } from '../../utilities/require-project-module';
77
import { WebpackConfigOptions } from '../webpack-config';
8+
import { BundleBudgetPlugin } from '../../plugins/bundle-budget';
89
import { CleanCssWebpackPlugin } from '../../plugins/cleancss-webpack-plugin';
910
import { ScriptsWebpackPlugin } from '../../plugins/scripts-webpack-plugin';
1011

@@ -252,6 +253,7 @@ export function getCommonConfig(wco: WebpackConfigOptions) {
252253
noEmitOnErrors: true,
253254
minimizer: [
254255
new HashedModuleIdsPlugin(),
256+
new BundleBudgetPlugin({ budgets: appConfig.budgets }),
255257
new CleanCssWebpackPlugin({
256258
sourceMap: buildOptions.sourcemaps,
257259
// component styles retain their original file name

packages/@angular/cli/models/webpack-configs/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './browser';
22
export * from './common';
3-
export * from './production';
43
export * from './server';
54
export * from './styles';
65
export * from './test';

packages/@angular/cli/models/webpack-configs/production.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/@angular/cli/models/webpack-test-config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export class WebpackTestConfig extends NgCliWebpackConfig<WebpackTestOptions> {
2121
const webpackConfigs = [
2222
getCommonConfig(this.wco),
2323
getStylesConfig(this.wco),
24-
this.getTargetConfig(this.wco),
2524
getNonAotTestConfig(this.wco),
2625
getTestConfig(this.wco)
2726
];

packages/@angular/cli/utilities/service-worker/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Filesystem } from '@angular/service-worker/config';
2-
import { oneLine } from 'common-tags';
2+
import { oneLine, stripIndent } from 'common-tags';
33
import * as crypto from 'crypto';
44
import * as fs from 'fs';
55
import * as path from 'path';
@@ -57,13 +57,25 @@ export function usesServiceWorker(projectRoot: string): boolean {
5757
swPackageJsonPath = resolveProjectModule(projectRoot, '@angular/service-worker/package.json');
5858
} catch (_) {
5959
// @angular/service-worker is not installed
60-
return false;
60+
throw new Error(stripIndent`
61+
Your project is configured with serviceWorker = true, but @angular/service-worker
62+
is not installed. Run \`npm install --save-dev @angular/service-worker\`
63+
and try again, or run \`ng set apps.0.serviceWorker=false\` in your .angular-cli.json.
64+
`);
6165
}
6266

6367
const swPackageJson = fs.readFileSync(swPackageJsonPath).toString();
6468
const swVersion = JSON.parse(swPackageJson)['version'];
6569

66-
return semver.gte(swVersion, NEW_SW_VERSION);
70+
if (!semver.gte(swVersion, NEW_SW_VERSION)) {
71+
throw new Error(stripIndent`
72+
The installed version of @angular/service-worker is ${swVersion}. This version of the CLI
73+
requires the @angular/service-worker version to satisfy ${NEW_SW_VERSION}. Please upgrade
74+
your service worker version.
75+
`);
76+
}
77+
78+
return true;
6779
}
6880

6981
export function augmentAppWithServiceWorker(projectRoot: string, appRoot: string,

0 commit comments

Comments
 (0)