{"id":15389620,"url":"https://github.com/joshwnj/cmz","last_synced_at":"2025-04-15T21:08:25.336Z","repository":{"id":57201265,"uuid":"65439140","full_name":"joshwnj/cmz","owner":"joshwnj","description":"Same great CSS Modules taste, Zero sugar.","archived":false,"fork":false,"pushed_at":"2020-05-25T04:09:39.000Z","size":1223,"stargazers_count":19,"open_issues_count":5,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T01:13:40.210Z","etag":null,"topics":["css","css-in-js","css-modules","immutable-css"],"latest_commit_sha":null,"homepage":"https://joshwnj.github.io/cmz/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joshwnj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-11T04:45:33.000Z","updated_at":"2025-03-10T19:26:23.000Z","dependencies_parsed_at":"2022-09-15T11:22:12.546Z","dependency_job_id":null,"html_url":"https://github.com/joshwnj/cmz","commit_stats":null,"previous_names":[],"tags_count":50,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshwnj%2Fcmz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshwnj%2Fcmz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshwnj%2Fcmz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joshwnj%2Fcmz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joshwnj","download_url":"https://codeload.github.com/joshwnj/cmz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661707,"owners_count":21141450,"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","css-in-js","css-modules","immutable-css"],"created_at":"2024-10-01T15:02:33.385Z","updated_at":"2025-04-15T21:08:25.299Z","avatar_url":"https://github.com/joshwnj.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# cmz\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/joshwnj/cmz.svg)](https://greenkeeper.io/)\n\n[![Build Status](https://secure.travis-ci.org/joshwnj/cmz.png)](http://travis-ci.org/joshwnj/cmz)\n\n**CSS Modules Zero:** A low-sugar variant of CSS Modules that runs in node and in the browser.\n\n## Example\n\n- [take a look at the example](https://github.com/joshwnj/cmz/tree/master/example) or [view it online](https://joshwnj.github.io/cmz/)\n- you can also [try it out on codepen](http://codepen.io/joshwnj/pen/zZNERK?editors=0010#0\n)\n\nThere is some [more background context in the wiki](https://github.com/joshwnj/cmz/wiki).\n\n## How to get started\n\nFirst add it to your project with `npm install cmz`\n\nIn your component `widget.js` you want to style with a CSS Module. Add this to the top:\n\n```js\nconst cmz = require('cmz')\n\n// Define a single class.\nconst myAmazingClass = cmz(`\n  font-style: italic\n  color: magenta\n`)\n\n// This is the equivalent of\n//\n//  .myAmazingClass {\n//    font-style: italic;\n//    color: magenta;\n//  }\n\n// Now you can use that class:\ndocument.body.innerHTML = `\u003ch1 class=\"${myAmazingclass}\"\u003ecmz demo\u003c/h1\u003e`\n\n// The css is automatically added to the document's stylesheet.\n```\n\n### Pseudoselectors\n\nIf you want a class with a pseudoselector, we can use the `\u0026` placeholder (which is replaced with the class's unique name):\n\n```js\nconst classWithPseudos = cmz(`\n\u0026 {\n  color: magenta\n}\n\n\u0026:hover {\n  color: cyan\n}\n`)\n```\n\n### Composition\n\nA useful pattern with CSS Modules is to define a library of common styles, and then compose them together.\n\n```js\n// typography.js\n\nimport cmz from 'cmz'\n\nexport const bigText = cmz(`\n  font-size: 48px\n  letter-spacing: .1rem\n  text-transform: uppercase\n`)\n\nexport const highlight = cmz(`\n  color: cyan\n  font-weight: bold\n`)\n```\n\nTo compose, pass an array of classes. It's fine to mix new classes with existing ones:\n\n```js\n// heading.js\n\nimport cmz from 'cmz'\nimport typo from './typography'\n\nconst heading = cmz(`\n  padding: 16px\n  border-bottom: 1px solid #000\n`,\n  typo.bigText,\n  typo.highlight\n)\n\nexport default function () {\n  return `\u003ch1 class=\"${heading}\"\u003ecmz demo\u003c/h1\u003e`\n}\n```\n\n### Can `cmz` generate a `.css` file?\n\nYes!\n\nBy default `cmz` adds all css to the page at runtime via a `\u003cstyle\u003e` tag. In a lot of cases this is fine, and will save you a network request as it's all bundled in the one `.js` file.\n\nTo extract css to a separate `.css` file (and result in a smaller `.js` bundle) there are 3 steps:\n\n- create the js bundle as usual, with the [cmz-names](https://github.com/joshwnj/babel-plugin-cmz-names) babel plugin\n- server-side-render your frontend, so that `cmz` can collect all of the necessary styles and write a `.css` file\n- run the `cmz-min` script to trim the extracted css rules from your js bundle\n\nTo see this in action take a look at the [example](https://github.com/joshwnj/cmz/tree/master/example).\n\n### Are animations automatically scoped?\n\nBy default, animations are left untouched. But you can create unique animation names by using the `?` placeholder. The animation will be created with the same base-name as the class:\n\n```js\nconst fadeAnim = cmz(`\n  \u0026 {\n    animation: ? 1s infinite\n  }\n\n  @keyframes ? {\n    0% { opacity: 1 }\n    50% { opacity: 0 }\n  }\n`)\n```\n\nBecause the animation is coupled with a class, they can be applied as compositions, eg:\n\n```js\nconst myFadingThing = cmz(\n  'width: 50%',\n  fadeAnim\n)\n```\n\n### Does `cmz` add vendor-prefixes?\n\nNot yet, but it will soon :) If this is important to you I'd love to help you make a PR :)\n\n## Thanks\n\nto the [CSS Modules team](https://github.com/orgs/css-modules/people)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshwnj%2Fcmz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoshwnj%2Fcmz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoshwnj%2Fcmz/lists"}