Skip to content

Commit 8391c3b

Browse files
rene-leanixMRHarrison
authored andcommitted
feat(autoprefixer) Hook up autoprefixer for less, scss, and css.
[Autoprefixer](https://github.com/postcss/autoprefixer) is a tool that uses data from caniuse.com to add vendor prefixes for styles that need them. It saves developers from having to manually prefix things, and is widely used these days. Since it's available as a postcss plugin, it makes sense to inlcude it in the angular-cli build step by default. This implementation uses the default browser targeting settings: last two versions, or whatever's in the user's project's [browserslist](https://github.com/ai/browserslist). Closes angular#1512. Close angular#2852
1 parent 2cc2c40 commit 8391c3b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/angular-cli/models/webpack-build-common.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {GlobCopyWebpackPlugin} from '../plugins/glob-copy-webpack-plugin';
44
import {BaseHrefWebpackPlugin} from '@angular-cli/base-href-webpack';
55

66
const HtmlWebpackPlugin = require('html-webpack-plugin');
7+
const autoprefixer = require('autoprefixer');
78

89

910
export function getWebpackCommonConfig(
@@ -113,7 +114,13 @@ export function getWebpackCommonConfig(
113114
new GlobCopyWebpackPlugin({
114115
patterns: appConfig.assets,
115116
globOptions: {cwd: appRoot, dot: true, ignore: '**/.gitkeep'}
116-
})
117+
}),
118+
new webpack.LoaderOptionsPlugin({
119+
test: /\.(css|scss|sass|less|styl)$/,
120+
options: {
121+
postcss: [ autoprefixer() ]
122+
},
123+
}),
117124
],
118125
node: {
119126
fs: 'empty',

tests/e2e/tests/build/styles/css.ts renamed to tests/e2e/tests/build/styles/styles-array.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export default function() {
1111
@import './imported-styles.css';
1212
1313
body { background-color: blue; }
14+
15+
div { flex: 1 }
1416
`,
1517
'src/imported-styles.css': `
1618
p { background-color: red; }
@@ -38,6 +40,9 @@ export default function() {
3840
.then(() => ng('build'))
3941
.then(() => expectFileToMatch('dist/styles.bundle.js', 'body { background-color: blue; }'))
4042
.then(() => expectFileToMatch('dist/styles.bundle.js', 'p { background-color: red; }'))
43+
.then(() => expectFileToMatch(
44+
'dist/styles.bundle.js',
45+
'div { -webkit-box-flex: 1; -ms-flex: 1; flex: 1 }'))
4146
.then(() => expectFileToMatch('dist/styles.bundle.js', /.outer.*.inner.*background:\s*#[fF]+/))
4247
.then(() => expectFileToMatch('dist/styles.bundle.js', /.upper.*.lower.*background.*#def/))
4348

0 commit comments

Comments
 (0)