Skip to content

Commit 9337617

Browse files
alan-agius4clydin
authored andcommitted
feat(@angular-devkit/build-angular): add postcss-preset-env with stage 3 features
With this change we add `postcss-preset-env` with stage 3 features. This stage includes support for: - all property - break properties - custom properties - font-variant property - gap properties - media query ranges See https://preset-env.cssdb.org/features#stage-3
1 parent f424529 commit 9337617

File tree

6 files changed

+383
-27
lines changed

6 files changed

+383
-27
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"@types/npm-package-arg": "^6.1.0",
115115
"@types/parse5-html-rewriting-stream": "^5.1.2",
116116
"@types/pidusage": "^2.0.1",
117+
"@types/postcss-preset-env": "^6.7.1",
117118
"@types/progress": "^2.0.3",
118119
"@types/request": "^2.47.1",
119120
"@types/resolve": "^1.17.1",
@@ -129,7 +130,6 @@
129130
"@yarnpkg/lockfile": "1.1.0",
130131
"ajv": "6.12.6",
131132
"ansi-colors": "4.1.1",
132-
"autoprefixer": "10.2.4",
133133
"babel-loader": "8.2.2",
134134
"bootstrap": "^4.0.0",
135135
"browserslist": "^4.9.1",
@@ -193,6 +193,7 @@
193193
"postcss": "8.2.5",
194194
"postcss-import": "14.0.0",
195195
"postcss-loader": "4.2.0",
196+
"postcss-preset-env": "6.7.0",
196197
"prettier": "^2.0.0",
197198
"protractor": "~7.0.0",
198199
"puppeteer": "7.0.1",

packages/angular_devkit/build_angular/BUILD.bazel

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ ts_library(
130130
"@npm//@types/minimatch",
131131
"@npm//@types/node",
132132
"@npm//@types/parse5-html-rewriting-stream",
133+
"@npm//@types/postcss-preset-env",
133134
"@npm//@types/rimraf",
134135
"@npm//@types/semver",
135136
"@npm//@types/speed-measure-webpack-plugin",
@@ -139,7 +140,6 @@ ts_library(
139140
"@npm//@types/webpack-sources",
140141
"@npm//ajv",
141142
"@npm//ansi-colors",
142-
"@npm//autoprefixer",
143143
"@npm//babel-loader",
144144
"@npm//browserslist",
145145
"@npm//cacache",
@@ -171,6 +171,7 @@ ts_library(
171171
"@npm//postcss",
172172
"@npm//postcss-import",
173173
"@npm//postcss-loader",
174+
"@npm//postcss-preset-env",
174175
"@npm//raw-loader",
175176
"@npm//regenerator-runtime",
176177
"@npm//resolve-url-loader",

packages/angular_devkit/build_angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
2222
"@ngtools/webpack": "0.0.0",
2323
"ansi-colors": "4.1.1",
24-
"autoprefixer": "10.2.4",
2524
"babel-loader": "8.2.2",
2625
"browserslist": "^4.9.1",
2726
"cacache": "15.0.5",
@@ -51,6 +50,7 @@
5150
"postcss": "8.2.5",
5251
"postcss-import": "14.0.0",
5352
"postcss-loader": "4.2.0",
53+
"postcss-preset-env": "6.7.0",
5454
"raw-loader": "4.0.2",
5555
"regenerator-runtime": "0.13.7",
5656
"resolve-url-loader": "3.1.2",

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { tags } from '@angular-devkit/core';
1010
import * as fs from 'fs';
1111
import * as path from 'path';
1212
import * as webpack from 'webpack';
13+
import { BuildBrowserFeatures } from '../../utils/build-browser-features';
1314
import { WebpackConfigOptions } from '../../utils/build-options';
1415
import {
1516
AnyComponentStyleBudgetChecker,
@@ -21,9 +22,9 @@ import { assetNameTemplateFactory, getOutputHashFormat, normalizeExtraEntryPoint
2122

2223
// tslint:disable-next-line:no-big-function
2324
export function getStylesConfig(wco: WebpackConfigOptions) {
24-
const autoprefixer = require('autoprefixer');
2525
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2626
const postcssImports = require('postcss-import');
27+
const postcssPresetEnv: typeof import('postcss-preset-env') = require('postcss-preset-env');
2728

2829
const { root, buildOptions } = wco;
2930
const entryPoints: { [key: string]: [string, ...string[]] } = {};
@@ -189,6 +190,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
189190
}
190191
}
191192

193+
const { supportedBrowsers } = new BuildBrowserFeatures(wco.projectRoot);
192194
const postcssOptionsCreator = (sourceMap: boolean, extracted: boolean | undefined) => {
193195
return (loader: webpack.loader.LoaderContext) => ({
194196
map: sourceMap && {
@@ -223,7 +225,12 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
223225
extracted,
224226
}),
225227
...extraPostcssPlugins,
226-
autoprefixer(),
228+
postcssPresetEnv({
229+
// tslint:disable-next-line: no-any
230+
browsers: supportedBrowsers as any, // Typings only allow a string
231+
autoprefixer: true,
232+
stage: 3,
233+
}),
227234
],
228235
});
229236
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expectFileToMatch, replaceInFile, writeMultipleFiles } from '../../../utils/fs';
2+
import { ng } from '../../../utils/process';
3+
4+
export default async function () {
5+
await writeMultipleFiles({
6+
'src/styles.css': `a {
7+
all: initial;
8+
}`,
9+
});
10+
11+
// Enable IE 11 support
12+
await replaceInFile(
13+
'.browserslistrc',
14+
'not IE 11',
15+
'IE 11',
16+
);
17+
18+
await ng('build');
19+
await expectFileToMatch('dist/test-project/styles.css', 'z-index: auto');
20+
await expectFileToMatch('dist/test-project/styles.css', 'all: initial');
21+
}

0 commit comments

Comments
 (0)