Skip to content

Commit 145a8e7

Browse files
clydinalan-agius4
authored andcommitted
refactor(@angular-devkit/build-angular): use built-in CSS vendor prefixing in esbuild
As of esbuild v0.18.9, vendor prefixing of CSS is now supported. The esbuild target option is generated from a project's browserslist and the vendor prefixing will reflect the configured browsers for a project. This improvement allows for the removal of the postcss autoprefixer plugin from the build pipeline. This can provide a performance benefit for projects especially when project stylesheets contain nothing that would require prefixing since postcss processing can potentially be skipped completely.
1 parent 9c02306 commit 145a8e7

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

packages/angular_devkit/build_angular/src/tools/esbuild/stylesheets/stylesheet-plugin-factory.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import createAutoPrefixerPlugin from 'autoprefixer';
109
import type { OnLoadResult, Plugin, PluginBuild } from 'esbuild';
1110
import glob from 'fast-glob';
1211
import assert from 'node:assert';
@@ -62,57 +61,35 @@ export interface StylesheetLanguage {
6261
}
6362

6463
export class StylesheetPluginFactory {
65-
private autoprefixer: import('postcss').Plugin | undefined;
66-
6764
constructor(
6865
private readonly options: StylesheetPluginOptions,
6966
private readonly cache?: LoadResultCache,
70-
) {
71-
const autoprefixer = createAutoPrefixerPlugin({
72-
overrideBrowserslist: options.browsers,
73-
ignoreUnknownVersions: true,
74-
});
75-
76-
// Autoprefixer currently does not contain a method to check if autoprefixer is required
77-
// based on the provided list of browsers. However, it does contain a method that returns
78-
// informational text that can be used as a replacement. The text "Awesome!" will be present
79-
// when autoprefixer determines no actions are needed.
80-
// ref: https://github.com/postcss/autoprefixer/blob/e2f5c26ff1f3eaca95a21873723ce1cdf6e59f0e/lib/info.js#L118
81-
const autoprefixerInfo = autoprefixer.info();
82-
const skipAutoprefixer = autoprefixerInfo.includes('Awesome!');
83-
84-
if (!skipAutoprefixer) {
85-
this.autoprefixer = autoprefixer;
86-
}
87-
}
67+
) {}
8868

8969
create(language: Readonly<StylesheetLanguage>): Plugin {
9070
// Return a noop plugin if no load actions are required
91-
if (!language.process && !this.autoprefixer && !this.options.tailwindConfiguration) {
71+
if (!language.process && !this.options.tailwindConfiguration) {
9272
return {
9373
name: 'angular-' + language.name,
9474
setup() {},
9575
};
9676
}
9777

98-
const { autoprefixer, cache, options } = this;
78+
const { cache, options } = this;
9979

10080
return {
10181
name: 'angular-' + language.name,
10282
async setup(build) {
103-
// Setup postcss if needed by either autoprefixer or tailwind
83+
// Setup postcss if needed by tailwind
10484
// TODO: Move this into the plugin factory to avoid repeat setup per created plugin
10585
let postcssProcessor: import('postcss').Processor | undefined;
106-
if (autoprefixer || options.tailwindConfiguration) {
86+
if (options.tailwindConfiguration) {
10787
postcss ??= (await import('postcss')).default;
10888
postcssProcessor = postcss();
10989
if (options.tailwindConfiguration) {
11090
const tailwind = await import(options.tailwindConfiguration.package);
11191
postcssProcessor.use(tailwind.default({ config: options.tailwindConfiguration.file }));
11292
}
113-
if (autoprefixer) {
114-
postcssProcessor.use(autoprefixer);
115-
}
11693
}
11794

11895
// Add a load callback to support inline Component styles

0 commit comments

Comments
 (0)