Skip to content

Commit 3c673a7

Browse files
committed
fix(@angular/cli): postCssOption
1 parent 4b0c7a3 commit 3c673a7

File tree

7 files changed

+61
-3
lines changed

7 files changed

+61
-3
lines changed

docs/documentation/angular-cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
- *preserveSymlinks* (`boolean`): Do not use the real path when resolving modules. Default is `false`.
8787
- *showCircularDependencies* (`boolean`): Show circular dependency warnings on builds. Default is `true`.
8888
- *namedChunks* (`boolean`): Use file name for lazy loaded chunks.
89+
- *withPostCssWarnings* (`boolean`): Flag to have post CSS warnings. Default is `true`.
8990
- *serve*: Properties to be passed to the serve command
9091
- *port* (`number`): The port the application will be served on. Default is `4200`.
9192
- *host* (`string`): The host the application will be served on. Default is `localhost`.

packages/@angular/cli/commands/build.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const Command = require('../ember-cli/lib/models/command');
1212
const config = CliConfig.fromProject() || CliConfig.fromGlobal();
1313
const buildConfigDefaults = config.getPaths('defaults.build', [
1414
'sourcemaps', 'baseHref', 'progress', 'poll', 'deleteOutputPath', 'preserveSymlinks',
15-
'showCircularDependencies', 'commonChunk', 'namedChunks'
15+
'showCircularDependencies', 'commonChunk', 'namedChunks', 'withPostCssWarnings'
1616
]);
1717

1818
// defaults for BuildOptions
@@ -207,6 +207,12 @@ export const baseBuildCommandOptions: any = [
207207
type: Boolean,
208208
description: 'Flag to prevent building an app shell',
209209
default: false
210+
},
211+
{
212+
name: 'with-post-css-warnings',
213+
type: Boolean,
214+
description: 'Flag to have post CSS warnings.',
215+
default: buildConfigDefaults['withPostCssWarnings']
210216
}
211217
];
212218

packages/@angular/cli/lib/config/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@
519519
"namedChunks": {
520520
"description": "Use file name for lazy loaded chunks.",
521521
"type": "boolean"
522+
},
523+
"withPostCssWarnings": {
524+
"description": "Flag to have post CSS warnings.",
525+
"type": "boolean",
526+
"default": true
522527
}
523528
}
524529
},

packages/@angular/cli/models/build-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ export interface BuildOptions {
3333
forceTsCommonjs?: boolean;
3434
serviceWorker?: boolean;
3535
skipAppShell?: boolean;
36+
withPostCssWarnings?: boolean;
3637
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
105105
extractCss: false,
106106
namedChunks: true,
107107
aot: false,
108-
buildOptimizer: false
108+
buildOptimizer: false,
109+
withPostCssWarnings: true
109110
},
110111
production: {
111112
environment: 'prod',

packages/@angular/cli/models/webpack-configs/styles.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
4646
// Convert absolute resource URLs to account for base-href and deploy-url.
4747
const baseHref = wco.buildOptions.baseHref || '';
4848
const deployUrl = wco.buildOptions.deployUrl || '';
49+
const withPostCssWarnings = wco.buildOptions.withPostCssWarnings || true;
4950

5051
const postcssPluginCreator = function() {
5152
// safe settings based on: https://github.com/ben-eb/cssnano/issues/358#issuecomment-283696193
@@ -86,7 +87,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
8687
}
8788
]),
8889
autoprefixer(),
89-
customProperties({ preserve: true })
90+
customProperties({ preserve: true, warnings: withPostCssWarnings })
9091
].concat(
9192
minimizeCss ? [cssnano(minimizeOptions)] : []
9293
);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {
2+
killAllProcesses,
3+
waitForAnyProcessOutputToMatch,
4+
execAndWaitForOutputToMatch
5+
} from '../../utils/process';
6+
import { appendToFile } from '../../utils/fs';
7+
import { getGlobalVariable } from '../../utils/env';
8+
import { updateJsonFile } from '../../utils/project';
9+
10+
const webpackGoodRegEx = /webpack: Compiled successfully./;
11+
const webpackWarningRegEx = /webpack: Compiled with warnings./;
12+
13+
export default function () {
14+
if (process.platform.startsWith('win')) {
15+
return Promise.resolve();
16+
}
17+
// Skip this in ejected tests.
18+
if (getGlobalVariable('argv').eject) {
19+
return Promise.resolve();
20+
}
21+
22+
23+
return execAndWaitForOutputToMatch('ng', ['serve'], webpackGoodRegEx)
24+
// Should trigger a rebuild.
25+
.then(() => appendToFile('src/app/app.component.css', 'body { color: var(--white); }'))
26+
// Should see some warnings
27+
.then(() => waitForAnyProcessOutputToMatch(webpackWarningRegEx, 10000))
28+
.then(() => killAllProcesses(), (err: any) => {
29+
killAllProcesses();
30+
throw err;
31+
})
32+
// update withPostCssWarnings flag
33+
.then(() => updateJsonFile('.angular-cli.json', configJson => {
34+
configJson['defaults']['build'] = {};
35+
configJson['defaults']['build']['withPostCssWarnings'] = false
36+
}))
37+
// should remove warnings
38+
.then(() => execAndWaitForOutputToMatch('ng', ['serve'], webpackGoodRegEx))
39+
.then(() => killAllProcesses(), (err: any) => {
40+
killAllProcesses();
41+
throw err;
42+
})
43+
}

0 commit comments

Comments
 (0)