10 releases (1 stable)
Uses new Rust 2024
| 1.0.0 | Oct 4, 2025 |
|---|---|
| 0.1.8 | May 16, 2024 |
#1330 in HTTP server
410 downloads per month
33KB
549 lines
const-css-minify
Include a minified css file as an inline const in your high-performance compiled web application.
use const_css_minify::minify;
const CSS: &str = minify!("./path/to/style.css");
const_css_minify is not a good solution if your css changes out-of-step with your binary, as
you will not be able to change the css without recompiling your application.
const_css_minify will:
- remove unneeded whitespace and linebreaks
- remove comments
- remove unneeded trailing semicolon in each declaration block
- opportunistically minify colors specified either by literal hex values or by
rgb(),rgba(),hsl()andhsla()functions (in either legacy syntax with commas or modern syntax without commas) without changing the color. e.g.#ffffffwill be substituted with#fff,hsl(180 50 50)with#40bfbf,rgba(20%, 40%, 60%, 0.8)with#369c, etc.const-css-minifywill not attempt to calculate nested/complicated/relative rgb expressions (which will be passed through unadulturated for the end user's browser to figure out for itself) but many simple/literal expressions will be resolved and minified. - silently ignore css syntax errors originating in your source file*, and in so doing possibly elicit slightly different failure modes from renderers by altering the placement of whitespace around misplaced operators
const_css_minify will not:
- compress your css using
gz,brordeflate - change the semantic meaning of your semantically valid css
- make any substitutions other than identical literal colors
- alert you to invalid css* - it's not truly parsing the css, just scanning for and removing characters it identifies as unnecessary
const_css_minify is a lightweight solution - the current version of const_css_minify has
zero dependencies outside rust's built-in std and proc_macro libraries.
This project is licensed under the terms of the MIT License.