Skip to content

Commit 98abbd0

Browse files
author
Seth Davenport
committed
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 #1512.
1 parent 86021a0 commit 98abbd0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
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(
@@ -131,7 +132,13 @@ export function getWebpackCommonConfig(
131132
new GlobCopyWebpackPlugin({
132133
patterns: appConfig.assets,
133134
globOptions: {cwd: appRoot, dot: true, ignore: '**/.gitkeep'}
134-
})
135+
}),
136+
new webpack.LoaderOptionsPlugin({
137+
test: /\.(css|scss|sass|less|styl)$/,
138+
options: {
139+
postcss: [ autoprefixer() ]
140+
},
141+
}),
135142
],
136143
node: {
137144
fs: 'empty',

tests/e2e/tests/build/styles/css.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@ export default function() {
88
@import './imported-styles.css';
99
1010
body { background-color: blue; }
11+
12+
div { flex: 1 }
1113
`,
1214
'src/imported-styles.css': `
1315
p { background-color: red; }
1416
`
1517
})
1618
.then(() => ng('build'))
1719
.then(() => expectFileToMatch('dist/styles.bundle.js', 'body { background-color: blue; }'))
18-
.then(() => expectFileToMatch('dist/styles.bundle.js', 'p { background-color: red; }'));
20+
.then(() => expectFileToMatch('dist/styles.bundle.js', 'p { background-color: red; }'))
21+
.then(() => expectFileToMatch(
22+
'dist/styles.bundle.js',
23+
'div { -webkit-box-flex: 1; -ms-flex: 1; flex: 1 }'));
1924
}

0 commit comments

Comments
 (0)