Skip to content

fix(@angular/cli): postCssOption #8667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/documentation/angular-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
- *preserveSymlinks* (`boolean`): Do not use the real path when resolving modules. Default is `false`.
- *showCircularDependencies* (`boolean`): Show circular dependency warnings on builds. Default is `true`.
- *namedChunks* (`boolean`): Use file name for lazy loaded chunks.
- *withPostCssWarnings* (`boolean`): Flag to have post CSS warnings. Default is `true`.
- *serve*: Properties to be passed to the serve command
- *port* (`number`): The port the application will be served on. Default is `4200`.
- *host* (`string`): The host the application will be served on. Default is `localhost`.
Expand Down
8 changes: 7 additions & 1 deletion packages/@angular/cli/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Command = require('../ember-cli/lib/models/command');
const config = CliConfig.fromProject() || CliConfig.fromGlobal();
const buildConfigDefaults = config.getPaths('defaults.build', [
'sourcemaps', 'baseHref', 'progress', 'poll', 'deleteOutputPath', 'preserveSymlinks',
'showCircularDependencies', 'commonChunk', 'namedChunks'
'showCircularDependencies', 'commonChunk', 'namedChunks', 'withPostCssWarnings'
]);

// defaults for BuildOptions
Expand Down Expand Up @@ -207,6 +207,12 @@ export const baseBuildCommandOptions: any = [
type: Boolean,
description: 'Flag to prevent building an app shell',
default: false
},
{
name: 'with-post-css-warnings',
type: Boolean,
description: 'Flag to have post CSS warnings.',
default: buildConfigDefaults['withPostCssWarnings']
}
];

Expand Down
5 changes: 5 additions & 0 deletions packages/@angular/cli/lib/config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@
"namedChunks": {
"description": "Use file name for lazy loaded chunks.",
"type": "boolean"
},
"withPostCssWarnings": {
"description": "Flag to have post CSS warnings.",
"type": "boolean",
"default": true
}
}
},
Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/models/build-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ export interface BuildOptions {
forceTsCommonjs?: boolean;
serviceWorker?: boolean;
skipAppShell?: boolean;
withPostCssWarnings?: boolean;
}
3 changes: 2 additions & 1 deletion packages/@angular/cli/models/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export class NgCliWebpackConfig<T extends BuildOptions = BuildOptions> {
extractCss: false,
namedChunks: true,
aot: false,
buildOptimizer: false
buildOptimizer: false,
withPostCssWarnings: true
},
production: {
environment: 'prod',
Expand Down
3 changes: 2 additions & 1 deletion packages/@angular/cli/models/webpack-configs/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
// Convert absolute resource URLs to account for base-href and deploy-url.
const baseHref = wco.buildOptions.baseHref || '';
const deployUrl = wco.buildOptions.deployUrl || '';
const withPostCssWarnings = wco.buildOptions.withPostCssWarnings || true;

const postcssPluginCreator = function() {
// safe settings based on: https://github.com/ben-eb/cssnano/issues/358#issuecomment-283696193
Expand Down Expand Up @@ -86,7 +87,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) {
}
]),
autoprefixer(),
customProperties({ preserve: true })
customProperties({ preserve: true, warnings: withPostCssWarnings })
].concat(
minimizeCss ? [cssnano(minimizeOptions)] : []
);
Expand Down
43 changes: 43 additions & 0 deletions tests/e2e/tests/build/with-post-css-warnings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
killAllProcesses,
waitForAnyProcessOutputToMatch,
execAndWaitForOutputToMatch
} from '../../utils/process';
import { appendToFile } from '../../utils/fs';
import { getGlobalVariable } from '../../utils/env';
import { updateJsonFile } from '../../utils/project';

const webpackGoodRegEx = /webpack: Compiled successfully./;
Copy link

@YoannBureau YoannBureau Dec 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to webpackSuccessRegEx

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do this, but it won't fix failing tests right?

const webpackWarningRegEx = /webpack: Compiled with warnings./;

export default function () {
if (process.platform.startsWith('win')) {
return Promise.resolve();
}
// Skip this in ejected tests.
if (getGlobalVariable('argv').eject) {
return Promise.resolve();
}


return execAndWaitForOutputToMatch('ng', ['serve'], webpackGoodRegEx)
// Should trigger a rebuild.
.then(() => appendToFile('src/app/app.component.css', 'body { color: var(--white); }'))
// Should see some warnings
.then(() => waitForAnyProcessOutputToMatch(webpackWarningRegEx, 10000))
.then(() => killAllProcesses(), (err: any) => {
killAllProcesses();
throw err;
})
// update withPostCssWarnings flag
.then(() => updateJsonFile('.angular-cli.json', configJson => {
configJson['defaults']['build'] = {};
configJson['defaults']['build']['withPostCssWarnings'] = false
}))
// should remove warnings
.then(() => execAndWaitForOutputToMatch('ng', ['serve'], webpackGoodRegEx))
.then(() => killAllProcesses(), (err: any) => {
killAllProcesses();
throw err;
})
}