Skip to content

Commit 5e72056

Browse files
committed
perf(@angular-devkit/build-angular): use CSS optimization plugin that leverages workers
With this change we use `css-minimizer-webpack-plugin` which leverages workers and also webpack cache. (cherry picked from commit 7e04bb3)
1 parent 3943f5c commit 5e72056

File tree

7 files changed

+61
-228
lines changed

7 files changed

+61
-228
lines changed

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@
9696
"@types/babel__template": "7.4.0",
9797
"@types/cacache": "^15.0.0",
9898
"@types/caniuse-lite": "^1.0.0",
99-
"@types/copy-webpack-plugin": "^6.0.0",
100-
"@types/cssnano": "^4.0.0",
99+
"@types/copy-webpack-plugin": "^8.0.0",
101100
"@types/debug": "^4.1.2",
102101
"@types/express": "^4.16.0",
103102
"@types/find-cache-dir": "^3.0.0",
@@ -143,7 +142,7 @@
143142
"core-js": "3.12.0",
144143
"critters": "0.0.10",
145144
"css-loader": "5.2.4",
146-
"cssnano": "5.0.2",
145+
"css-minimizer-webpack-plugin": "3.0.0",
147146
"debug": "^4.1.1",
148147
"enhanced-resolve": "5.7.0",
149148
"eslint": "7.25.0",

packages/angular_devkit/build_angular/BUILD.bazel

+1-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ ts_library(
121121
"@npm//@types/cacache",
122122
"@npm//@types/caniuse-lite",
123123
"@npm//@types/copy-webpack-plugin",
124-
"@npm//@types/cssnano",
125124
"@npm//@types/find-cache-dir",
126125
"@npm//@types/glob",
127126
"@npm//@types/inquirer",
@@ -147,7 +146,7 @@ ts_library(
147146
"@npm//core-js",
148147
"@npm//critters",
149148
"@npm//css-loader",
150-
"@npm//cssnano",
149+
"@npm//css-minimizer-webpack-plugin",
151150
"@npm//find-cache-dir",
152151
"@npm//glob",
153152
"@npm//https-proxy-agent",

packages/angular_devkit/build_angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"core-js": "3.12.0",
3131
"critters": "0.0.10",
3232
"css-loader": "5.2.4",
33-
"cssnano": "5.0.2",
33+
"css-minimizer-webpack-plugin": "3.0.0",
3434
"find-cache-dir": "3.3.1",
3535
"glob": "7.1.7",
3636
"https-proxy-agent": "5.0.0",

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

+21-10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,7 @@ import {
3636
import { findAllNodeModules } from '../../utils/find-up';
3737
import { Spinner } from '../../utils/spinner';
3838
import { addError } from '../../utils/webpack-diagnostics';
39-
import {
40-
DedupeModuleResolvePlugin,
41-
OptimizeCssWebpackPlugin,
42-
ScriptsWebpackPlugin,
43-
} from '../plugins';
39+
import { DedupeModuleResolvePlugin, ScriptsWebpackPlugin } from '../plugins';
4440
import {
4541
getEsVersionForFileName,
4642
getOutputHashFormat,
@@ -49,8 +45,6 @@ import {
4945
} from '../utils/helpers';
5046
import { IGNORE_WARNINGS } from '../utils/stats';
5147

52-
const TerserPlugin = require('terser-webpack-plugin');
53-
5448
// eslint-disable-next-line max-lines-per-function
5549
export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
5650
const { root, projectRoot, buildOptions, tsConfig } = wco;
@@ -320,20 +314,37 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
320314

321315
const extraMinimizers = [];
322316
if (stylesOptimization.minify) {
317+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
323318
extraMinimizers.push(
324-
new OptimizeCssWebpackPlugin({
325-
sourceMap: stylesSourceMap,
319+
new CssMinimizerPlugin({
326320
// component styles retain their original file name
327-
test: (file) => /\.(?:css|scss|sass|less|styl)$/.test(file),
321+
test: /\.(?:css|scss|sass|less|styl)$/,
322+
parallel: maxWorkers,
323+
minify: [CssMinimizerPlugin.cssnanoMinify],
324+
minimizerOptions: {
325+
preset: [
326+
'default',
327+
{
328+
// Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
329+
svgo: false,
330+
// Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
331+
calc: false,
332+
// Disable CSS rules sorted due to several issues #20693, https://github.com/ionic-team/ionic-framework/issues/23266 and https://github.com/cssnano/cssnano/issues/1054
333+
cssDeclarationSorter: false,
334+
},
335+
],
336+
},
328337
}),
329338
);
330339
}
331340

332341
if (scriptsOptimization) {
342+
const TerserPlugin = require('terser-webpack-plugin');
333343
const {
334344
GLOBAL_DEFS_FOR_TERSER,
335345
GLOBAL_DEFS_FOR_TERSER_WITH_AOT,
336346
} = require('@angular/compiler-cli');
347+
337348
const angularGlobalDefinitions = buildOptions.aot
338349
? GLOBAL_DEFS_FOR_TERSER_WITH_AOT
339350
: GLOBAL_DEFS_FOR_TERSER;

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

-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
// Exports the webpack plugins we use internally.
1010
export { AnyComponentStyleBudgetChecker } from './any-component-style-budget-checker';
11-
export {
12-
OptimizeCssWebpackPlugin,
13-
OptimizeCssWebpackPluginOptions,
14-
} from './optimize-css-webpack-plugin';
1511
export { ScriptsWebpackPlugin, ScriptsWebpackPluginOptions } from './scripts-webpack-plugin';
1612
export { SuppressExtractedTextChunksWebpackPlugin } from './suppress-entry-chunks-webpack-plugin';
1713
export { RemoveHashPlugin, RemoveHashPluginOptions } from './remove-hash-plugin';

packages/angular_devkit/build_angular/src/webpack/plugins/optimize-css-webpack-plugin.ts

-136
This file was deleted.

0 commit comments

Comments
 (0)