Skip to content

Commit 640a749

Browse files
JoostKclydin
authored andcommitted
perf(@angular-devkit/build-angular): load postcss-preset-env configuration 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.
1 parent 57f78e8 commit 640a749

File tree

1 file changed

+6
-5
lines changed
  • packages/angular_devkit/build_angular/src/webpack/configs

1 file changed

+6
-5
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
158158
}
159159

160160
const { supportedBrowsers } = new BuildBrowserFeatures(wco.projectRoot);
161+
const postcssPresetEnvPlugin = postcssPresetEnv({
162+
browsers: supportedBrowsers,
163+
autoprefixer: true,
164+
stage: 3,
165+
});
161166
const postcssOptionsCreator = (inlineSourcemaps: boolean, extracted: boolean | undefined) => {
162167
// eslint-disable-next-line @typescript-eslint/no-explicit-any
163168
const optionGenerator = (loader: any) => ({
@@ -195,11 +200,7 @@ export function getStylesConfig(wco: WebpackConfigOptions): webpack.Configuratio
195200
extracted,
196201
}),
197202
...extraPostcssPlugins,
198-
postcssPresetEnv({
199-
browsers: supportedBrowsers,
200-
autoprefixer: true,
201-
stage: 3,
202-
}),
203+
postcssPresetEnvPlugin,
203204
],
204205
});
205206
// postcss-loader fails when trying to determine configuration files for data URIs

0 commit comments

Comments
 (0)