Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(@angular-devkit/build-angular): disable CSS optimization parallelism for components styles #20886

Merged
merged 1 commit into from
May 21, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -313,30 +313,6 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
}

const extraMinimizers = [];
if (stylesOptimization.minify) {
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
extraMinimizers.push(
new CssMinimizerPlugin({
// component styles retain their original file name
test: /\.(?:css|scss|sass|less|styl)$/,
parallel: maxWorkers,
minify: [CssMinimizerPlugin.cssnanoMinify],
minimizerOptions: {
preset: [
'default',
{
// Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
svgo: false,
// Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
calc: false,
// 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
cssDeclarationSorter: false,
},
],
},
}),
);
}

if (scriptsOptimization) {
const TerserPlugin = require('terser-webpack-plugin');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ExtraEntryPoint } from '../../browser/schema';
import { SassWorkerImplementation } from '../../sass/sass-service';
import { BuildBrowserFeatures } from '../../utils/build-browser-features';
import { WebpackConfigOptions } from '../../utils/build-options';
import { maxWorkers } from '../../utils/environment-options';
import {
AnyComponentStyleBudgetChecker,
PostcssCliResources,
Expand Down Expand Up @@ -402,11 +403,54 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
});
}

const extraMinimizers = [];
if (buildOptions.optimization.styles.minify) {
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const minimizerOptions = {
preset: [
'default',
{
// Disable SVG optimizations, as this can cause optimizations which are not compatible in all browsers.
svgo: false,
// Disable `calc` optimizations, due to several issues. #16910, #16875, #17890
calc: false,
// 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
cssDeclarationSorter: false,
},
],
};

const globalBundlesRegExp = new RegExp(
`^(${Object.keys(entryPoints).join('|')})(\.[0-9a-f]{20})?.css$`,
);

extraMinimizers.push(
new CssMinimizerPlugin({
// Component styles retain their original file name
test: /\.(?:css|scss|sass|less|styl)$/,
parallel: false,
exclude: globalBundlesRegExp,
minify: [CssMinimizerPlugin.cssnanoMinify],
minimizerOptions,
}),
new CssMinimizerPlugin({
test: /\.css$/,
include: globalBundlesRegExp,
parallel: maxWorkers,
minify: [CssMinimizerPlugin.cssnanoMinify],
minimizerOptions,
}),
);
}

return {
entry: entryPoints,
module: {
rules: [...fileLanguageRules, ...inlineLanguageRules],
},
optimization: {
minimizer: extraMinimizers,
},
plugins: extraPlugins,
};
}