8000 Added autoprefixer · jasonruesch/angular-cli@d0ac100 · GitHub
[go: up one dir, main page]

Skip to content

Commit d0ac100

Browse files
author
Jason Ruesch
committed
Added autoprefixer
1 parent 2225027 commit d0ac100

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"@types/request": "0.0.30",
136136
"@types/rimraf": "0.0.25-alpha",
137137
"@types/webpack": "^1.12.22-alpha",
138+
"autoprefixer": "^6.5.1",
138139
"chai": "^3.5.0",
139140
"conventional-changelog": "^1.1.0",
140141
"dtsgenerator": "^0.7.1",

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +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-
7+
const autoprefixer = require('autoprefixer');
88

99
export function getWebpackCommonConfig(
1010
projectRoot: string,
@@ -131,6 +131,13 @@ export function getWebpackCommonConfig(
131131
new GlobCopyWebpackPlugin({
132132
patterns: appConfig.assets,
133133
globOptions: {cwd: appRoot, dot: true, ignore: '**/.gitkeep'}
134+
}),
135+
new webpack.LoaderOptionsPlugin({
136+
options: {
137+
postcss: function () {
138+
return [autoprefixer];
139+
}
140+
}
134141
})
135142
],
136143
node: {

packages/angular-cli/models/webpack-config.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
getWebpackMobileConfigPartial,
1212
getWebpackMobileProdConfigPartial
1313
} from './';
14+
import * as webpack from 'webpack';
1415

1516
export class NgCliWebpackConfig {
1617
// TODO: When webpack2 types are finished lets replace all these any types
@@ -45,13 +46,13 @@ export class NgCliWebpackConfig {
4546
let mobileConfigPartial = getWebpackMobileConfigPartial(this.ngCliProject.root, appConfig);
4647
let mobileProdConfigPartial = getWebpackMobileProdConfigPartial(this.ngCliProject.root,
4748
appConfig);
48-
baseConfig = webpackMerge(baseConfig, mobileConfigPartial);
49+
baseConfig = this.betterWebpackMerge(baseConfig, mobileConfigPartial);
4950
if (this.target == 'production') {
50-
targetConfigPartial = webpackMerge(targetConfigPartial, mobileProdConfigPartial);
51+
targetConfigPartial = this.betterWebpackMerge(targetConfigPartial, mobileProdConfigPartial);
5152
}
5253
}
5354

54-
this.config = webpackMerge(
55+
this.config = this.betterWebpackMerge(
5556
baseConfig,
5657
targetConfigPartial,
5758
typescriptConfigPartial
@@ -68,4 +69,43 @@ export class NgCliWebpackConfig {
6869
throw new Error("Invalid build target. Only 'development' and 'production' are available.");
6970
}
7071
}
72+
73+
betterWebpackMerge(baseConfig: any, targetConfig: any, targetTypeScriptConfig?: any) {
74+
let basePlugins = (baseConfig && baseConfig.plugins) || [];
75+
let targetPlugins = (targetConfig && targetConfig.plugins) || [];
76+
let targetTypeScriptPlugins = (targetTypeScriptConfig && targetTypeScriptConfig.plugins) || [];
77+
let baseOptionsPlugins = basePlugins
78+
.filter((plugin: any) => plugin instanceof webpack.LoaderOptionsPlugin)
79+
.map((plugin: any) => plugin.options.options );
80+
let targetOptionsPlugins = targetPlugins
81+
.filter((plugin: any) => plugin instanceof webpack.LoaderOptionsPlugin)
82+
.map((plugin: any) => plugin.options.options );
83+
let targetTypeScriptOptionsPlugins = targetTypeScriptPlugins
84+
.filter((plugin: any) => plugin instanceof webpack.LoaderOptionsPlugin)
85+
.map((plugin: any) => plugin.options.options );
86+
let mergedConfig = webpackMerge(baseConfig, targetConfig, targetTypeScriptConfig);
87+
if (baseOptionsPlugins.length > 0 || targetOptionsPlugins.length > 0 || targetTypeScriptOptionsPlugins.length > 0) {
88+
let mergedBase = baseOptionsPlugins.reduce((base: any, next: any) => {
89+
Object.assign(base, next);
90+
return base;
91+
}, {});
92+
let mergedTarget = targetOptionsPlugins.reduce((base: any, next: any) => {
93+
Object.assign(base, next);
94+
return base;
95+
}, {});
96+
let mergedTargetTypeScript = targetTypeScriptOptionsPlugins.reduce((base: any, next: any) => {
97+
Object.assign(base, next);
98+
return base;
99+
}, {});
100+
if (mergedConfig.plugins) {
101+
mergedConfig.plugins = mergedConfig.plugins.filter((plugin: any) => {
102+
return !(plugin instanceof webpack.LoaderOptionsPlugin);
103+
});
104+
mergedConfig.plugins.push(new webpack.LoaderOptionsPlugin({
105+
options: Object.assign(mergedBase, mergedTarget, mergedTargetTypeScript)
106+
}));
107+
}
108+
}
109+
return mergedConfig;
110+
}
71111
}

0 commit comments

Comments
 (0)
0