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.

clean-css appears to strip @font-face declarations

See original GitHub issue

Environment

  • clean-css version - npm ls clean-css: 4.1.11
  • node.js version - node -v: 6.9.4
  • operating system:

Configuration options

var CleanCSS = require('clean-css');
new CleanCSS({
  compatibility: 'ie10'
})

Input CSS

@font-face {
  font-family: 'FontAwesome';
  src: url('/fontawesome-webfont.eot?v=4.7.0');
  src: url('/fontawesome-webfont.eot?#iefix&v=4.7.0') format('embedded-opentype'),
    url('/fontawesome-webfont.woff2?v=4.7.0') format('woff2'),
    url('/fontawesome-webfont.woff?v=4.7.0') format('woff'),
    url('/fontawesome-webfont.ttf?v=4.7.0') format('truetype'),
    url('/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular') format('svg');
    //  src: url('/FontAwesome.otf') format('opentype'); // used when developing fonts
   font-weight: normal;
   font-style: normal;
}

.fa {
  display: inline-block;
  font: normal normal normal 10px/1 FontAwesome; // shortening font declaration
  font-size: inherit; // can't have font-size inherit on line above, so need to override
  text-rendering: auto; // optimizelegibility throws things off #1094
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.fa-lg {
  font-size: (4em / 3);
  line-height: (3em / 4);
  vertical-align: -15%;
}
.fa-2x { font-size: 2em; }
.fa-3x { font-size: 3em; }
.fa-4x { font-size: 4em; }
.fa-5x { font-size: 5em; }

/* ... and so on for a thousand+ lines of font class declarations, the rest isn't important */

Actual output CSS

.fa{display:inline-block;font:normal normal normal 10px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.fa-lg{font-size:1.33333em;line-height:.75em;vertical-align:-15%}.fa-2x{font-size:2em}.fa-3x{font-size:3em}
/* Note the @font-face declaration has been stripped */

Expected output CSS

@font-face {  font-family: 'FontAwesome';  src: url("/fontawesome-webfont.eot?v=4.7.0");  src: url("/fontawesome-webfont.eot?#iefix&v=4.7.0") format("embedded-opentype"), url("/fontawesome-webfont.woff2?v=4.7.0") format("woff2"), url("/fontawesome-webfont.woff?v=4.7.0") format("woff"), url("/fontawesome-webfont.ttf?v=4.7.0") format("truetype"), url("/fontawesome-webfont.svg?v=4.7.0#fontawesomeregular") format("svg");  font-weight: normal;  font-style: normal;}.fa{display:inline-block;font:normal normal normal 10px/1 FontAwesome;font-size:inherit;text-rendering:auto;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.fa-lg{font-size:1.33333em;line-height:.75em;vertical-align:-15%}.fa-2x{font-size:2em}.fa-3x{font-size:3em}
/*...*/

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
jakubpawlowiczcommented, Jan 21, 2021

I cannot replicate this issue anymore either on 4.1 branch or any newer.

Regarding removeUnusedAtRules option it is set to false by default indeed, however in no circumstances it should remove @font-face rules which are referenced in a stylesheet via font-family property set to the same value as font-family inside @font-face rule ( using font shorthand rather than font-family is also covered, see: https://github.com/jakubpawlowicz/clean-css/blob/master/lib/optimizer/level-2/remove-unused-at-rules.js#L139 and https://github.com/jakubpawlowicz/clean-css/blob/master/lib/optimizer/level-2/remove-unused-at-rules.js#L155 )

Please reopen this issue if needed.

1reaction
hummalcommented, Jul 26, 2018

Try to check if this is enabled:

Level 2 Optmizations

removeUnusedAtRules: true|false

Try to set it to false if set to true. Default is false

Read more comments on GitHub >

github_iconTop Results From Across the Web

clean-css appears to strip @font-face declarations · Issue #1035
Environment clean-css version - npm ls clean-css: 4.1.11 node.js version - node ... clean-css appears to strip @font-face declarations #1035.
Read more >
Configuring Web Fonts in 11ty with Global Data
Generating Font-Face Declarations Programmatically. With our global font config in place, we can begin generating @font-face declarations for ...
Read more >
clean-css-cli - npm Package Health Analysis - Snyk
Level 2 optimizations operate at rules or multiple properties level, e.g. can remove duplicate rules, remove properties redefined further down a stylesheet, or ......
Read more >
clean-css - npm
clean-css is a fast and efficient CSS optimizer for Node.js platform and any modern browser. According to tests it is one of the...
Read more >
How to use @font-face in CSS
The @font-face rule allows custom fonts to be loaded on a webpage. ... This format seems to be the winner and where all...
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