Skip to content

Commit

Permalink
perf(@angular-devkit/build-angular): load postcss-preset-env configur…
Browse files Browse the repository at this point in the history
…ation once

Loading the postcss-preset-env plugin includes building a mapping of unsupported
browsers by feature, which is somewhat expensive. In large compilations, this mapping
would be recomputed for each postcss-loader instance, as the plugin was recreated
for each loader invocation. By extracting the plugin instance outside of the dynamic
plugin computation, this overhead is avoided.

(cherry picked from commit 640a749)
  • Loading branch information
JoostK authored and clydin committed May 24, 2021
1 parent 71b0638 commit 2298562
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
}

const { supportedBrowsers } = new BuildBrowserFeatures(wco.projectRoot);
const postcssPresetEnvPlugin = postcssPresetEnv({
browsers: supportedBrowsers,
autoprefixer: true,
stage: 3,
});
const postcssOptionsCreator = (inlineSourcemaps: boolean, extracted: boolean | undefined) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const optionGenerator = (loader: any) => ({
Expand Down Expand Up @@ -195,11 +200,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
extracted,
}),
...extraPostcssPlugins,
postcssPresetEnv({
browsers: supportedBrowsers,
autoprefixer: true,
stage: 3,
}),
postcssPresetEnvPlugin,
],
});
// postcss-loader fails when trying to determine configuration files for data URIs
Expand Down

0 comments on commit 2298562

Please sign in to comment.