question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prod build re-orders and alters scss styles

See original GitHub issue

Versions

Angular CLI: 1.7.4 (e)
Node: 8.11.1
OS: win32 x64
Angular: 5.2.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cli: 1.7.4
@angular-devkit/build-optimizer: 0.3.2
@angular-devkit/core: 0.3.2
@angular-devkit/schematics: 0.3.2
@ngtools/json-schema: 1.2.0
@ngtools/webpack: 1.10.2
@schematics/angular: 0.3.2
@schematics/package-update: 0.3.2
typescript: 2.5.3
webpack-dev-server: 2.11.2
webpack: 3.11.0

Repro steps

  • Step 1 ng new test-proj-name --minimal true --style scss
  • Step 2 Paste following into styles.scss
$border-size: 1px;
$size: 0.125rem;
$color: #cccccc;

@mixin border-standard {
  border-width: $border-size;
  border-style: solid;
  border-radius: $size;
  border-color: $color;
}

th {
  @include border-standard;
  border-radius: 0;
  border-top: 0;
  border-right: 0;
  border-left: 0;
}
  • Step 3 ng build -ec
  • Step 4 View the following css output in dist/styles.bundle.css:
th {
  border-width: 1px;
  border-style: solid;
  border-radius: 0.125rem;
  border-color: #cccccc;
  border-radius: 0;
  border-top: 0;
  border-right: 0;
  border-left: 0; }
  • Step 5 ng build -prod
  • Step 6 View the following css output in dist/styles.GUID.bundle.css:
th{border-radius:0;border-top:0;border-right:0;border-left:0;border:1px solid #ccc}

Observed behavior

The border-width, border-style, and border-color have been combined into the single border shorthand property and moved to the end of the th selector when using the -prod flag. This negates the fact that border-left, border-right, and border-top properties were all set to 0 in the original scss to override the border. It is now these settings that are being overwritten.

Desired behavior

The order of the output css should not be altered from its original order in the scss. Everything would be fine in this specific use case if the border property had been added at the beginning of the selector, but I haven’t thought of other potential flaws here.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

1reaction
alan-agius4commented, Dec 6, 2018

This is expected since during production builds by default CSS gets minified to generate the smallest possible bundle and options get combined together using cleancss

If you have some code which is not side effect free you need to disable the optimisations for that piece of code using /* clean-css ignore:start */ and /* clean-css ignore:end */ comments

See https://github.com/jakubpawlowicz/clean-css#whats-new-in-version-42

1reaction
jprobertcommented, Sep 20, 2018

Is there any fix available related to this issue? Can’t get my css to work with ng build --prod --aot

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ordering flex items - CSS: Cascading Style Sheets | MDN
In this article, we will take a look at ways in which you can change the visual order of your content when using...
Read more >
Angular wrong css order in production build - Stack Overflow
I have a class which I defined in both files. When I serve the app with ng serve I see blue background (red...
Read more >
How To Apply CSS Styles to HTML with Cascade and Specificity
Cascading Style Sheets, better known as CSS, is the language for visual style and design on the web. With it, you can apply...
Read more >
A Few Different CSS Methods for Changing Display Order
In this tutorial we'll cover a few different CSS methods for reordering HTML elements. The Goal The layout we want to build is...
Read more >
Hacking CSS in MadCap Flare
Use CSS Variables · Use CSS Comments · Avoid Local Styling when Possible · Use the Flare Stylesheet Editor · Summary · Related...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found