clean-css appears to strip @font-face declarations
See original GitHub issueEnvironment
- 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:
- Created 5 years ago
- Reactions:2
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I cannot replicate this issue anymore either on 4.1 branch or any newer.
Regarding
removeUnusedAtRules
option it is set tofalse
by default indeed, however in no circumstances it should remove@font-face
rules which are referenced in a stylesheet viafont-family
property set to the same value asfont-family
inside@font-face
rule ( usingfont
shorthand rather thanfont-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.
Try to check if this is enabled:
Level 2 Optmizations
Try to set it to false if set to true. Default is false