{"id":15069911,"url":"https://github.com/prantlf/crass","last_synced_at":"2025-10-05T06:31:30.441Z","repository":{"id":57137888,"uuid":"193105598","full_name":"prantlf/crass","owner":"prantlf","description":"A CSS minifier and utility library for JavaScript","archived":false,"fork":true,"pushed_at":"2020-09-19T18:01:55.000Z","size":1072,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-09T17:56:05.810Z","etag":null,"topics":["css","minifier","parser"],"latest_commit_sha":null,"homepage":"http://mattbasta.com/crass","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mattbasta/crass","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-21T13:48:30.000Z","updated_at":"2020-09-19T18:01:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/prantlf/crass","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fcrass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fcrass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fcrass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fcrass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/crass/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235370461,"owners_count":18979093,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css","minifier","parser"],"created_at":"2024-09-25T01:45:29.894Z","updated_at":"2025-10-05T06:31:25.100Z","avatar_url":"https://github.com/prantlf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crass\r\n\r\nA CSS minification, pretty printing, and general utility library written in JS.\r\n\r\n[![Build Status](https://travis-ci.org/prantlf/crass.svg?branch=master)](https://travis-ci.org/prantlf/crass)\r\n[![Build status](https://ci.appveyor.com/api/projects/status/vwp3b6p6jf9563dg?svg=true)](https://ci.appveyor.com/project/mattbasta/crass)\r\n\r\nThis is a fork depending on up-to-date modules to avoid security issues.\r\n\r\n## Why Crass?\r\n\r\nCrass is one of only a handful of CSS minifiers that creates a full parse tree\r\nof the CSS. Most other CSS minifiers operate on the string source instead,\r\nwhich makes it impossible to perform all types of optimizations.\r\n\r\n**Pros:**\r\n\r\n- Better minification, particularly after gzip\r\n- Support for consistent pretty printing\r\n- Support for settled CSS4 and all of CSS3\r\n- Ability to strip obsolete tags (removed prefixes, old standard specs, etc.) by browser version\r\n- Convert all colors to their smallest possible form\r\n- Unsafe optimizations are opt-in only\r\n\r\n**Cons:**\r\n\r\n- Slower minification times\r\n- Cannot minify CSS with syntax errors\r\n- Certain \"CSS hacks\" that use invalid syntax are unsupported\r\n\r\n\r\n## Installation\r\n\r\nCrass is built with ES2015 and requires Node 6 or higher.\r\n\r\n```sh\r\nnpm install --save-dev @prantlf/crass\r\n```\r\n\r\n\r\n## API\r\n\r\n```js\r\nvar crass = require('@prantlf/crass');\r\n\r\n// Parse any valid CSS stylesheet:\r\nvar parsed = crass.parse('b {font-weight: bold;}');\r\n\r\n// Optimize the stylesheet:\r\nparsed = parsed.optimize();\r\n\r\n// Pretty print the stylesheet:\r\nconsole.log(parsed.pretty());\r\n\r\n// Print a minified version of the stylesheet:\r\nconsole.log(parsed.toString());\r\n\r\n// The constructors for the AST nodes used to represent the\r\n// parsed CSS are available on `crass.objects`.\r\n```\r\n\r\nImprovements on the API will be made in the future.\r\n\r\n## Command Line Interface\r\n\r\nIf you `npm install -g @prantlf/crass`, you'll get `crass` on your PATH.\r\n\r\n```bash\r\ncrass input.css [--optimize [--O1]] [--min x,y,z] [--pretty] [--saveie] [--css4]\r\n```\r\n\r\nIf you don't specify `--min`, crass will automatically default to the latest browser version from two years ago. At the time of writing, this is Chrome 39, Firefox 31, IE 11, and Opera 26.\r\n\r\n- **`--optimize`**: Flag to enable basic optimization\r\n- **`--O1`**: Only applies when `--optimize` is active. Flag to enable more advanced optimizations, though these are not guaranteed to work for all CSS.\r\n- **`--min`**: Setting this flag followed by a comma-separated list of browser versions will instruct Crass to strip CSS that would otherwise only apply to browsers older than the versions listed. For example, `--min ie9,fx30` would strip CSS that applies only to Firefox 29 and below and Internet Explorer 8 and below. The following prefixes are supported: `ie`, `op`, `fx`, `chr`\r\n- **`--pretty`**: Flag to enable pretty printing of output\r\n- **`--saveie`**: Flag to enable features to specifically support Internet Explorer 6 and below\r\n- **`--css4`**: Flag that allows optimized output to contain CSS4 features and syntax. This is not be supported in all modern browsers. You should only use this if you explicitly want CSS4 output.\r\n\r\n\r\n## Minification\r\n\r\nOutputting a crass object as a string will perform the equivalent of most CSS minification tools. The corresponding styles are output in the minimum amount of CSS possible, without any whitespace.\r\n\r\nSome minifiers also perform basic replacement and removal operations to replace certain patterns with other patterns. Using the `--optimize` and `--O1` flags on the command line and `.optimize()` and `.optimize({o1: true})` in the API will perform many of these operations along with additional optimizations that are not possible with traditional minification tools.\r\n\r\nFor example, since most minification tools do not truly parse CSS, they cannot perform any reordering or transformation. Crass, on the other hand, will rewrite code like this:\r\n\r\n```css\r\nb, c, a {\r\n    third: rgba(255, 255, 255, 0.9);\r\n    second: abc;\r\n    first: 50%;\r\n}\r\n```\r\n\r\ninto something that looks like:\r\n\r\n```css\r\na, b, c {\r\n    first: 50%;\r\n    second: abc;\r\n    third: hsla(0, 0%, 100%, 0.9);\r\n}\r\n```\r\n\r\nReordering selectors and declarations significantly improves minified code sizes. Colors can be translated between HSL/RGB/hex/etc. to use the smallest form.\r\n\r\n### Benchmarks\r\n\r\nCrass performs very well in many CSS minification benchmarks. See [goalsmashers' css minification benchmark](http://goalsmashers.github.io/css-minification-benchmark/) for more.\r\n\r\n\r\n## FAQ\r\n\r\n### Will there be a version that runs in the browser?\r\n\r\nYou can import Crass into your project using any appropriate build tool, like browserify or Webpack. Crass's importable modules have no dependencies on anything browser-incompatible.\r\n\r\nCheck out the Github pages for Crass for a simple browser-ready version:\r\n\r\n\u003chttp://www.mattbasta.com/crass/\u003e\r\n\r\n### What about comments? Docblocks?\r\n\r\nAll comments are ignored at the moment. Support for storing comment data may be added in the future, and contributions to add this support are welcome.\r\n\r\n### What about `@import` statements?\r\n\r\nCrass does not follow `@import` statements. You should use another CSS processing tool to resolve `@imports` and inline them appropriately, then use Crass to minify the result.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fcrass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fcrass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fcrass/lists"}