{"id":15250469,"url":"https://github.com/goto-bus-stop/tagged-css-modules","last_synced_at":"2026-01-03T14:07:11.055Z","repository":{"id":65374316,"uuid":"80549855","full_name":"goto-bus-stop/tagged-css-modules","owner":"goto-bus-stop","description":"Use CSS Modules inline in tagged template strings.","archived":false,"fork":false,"pushed_at":"2020-01-16T09:54:52.000Z","size":50,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-23T20:37:37.078Z","etag":null,"topics":["css-modules","template-literals"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/goto-bus-stop.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-31T18:40:25.000Z","updated_at":"2020-01-16T09:54:54.000Z","dependencies_parsed_at":"2023-01-20T01:15:43.406Z","dependency_job_id":null,"html_url":"https://github.com/goto-bus-stop/tagged-css-modules","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Ftagged-css-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Ftagged-css-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Ftagged-css-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/goto-bus-stop%2Ftagged-css-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/goto-bus-stop","download_url":"https://codeload.github.com/goto-bus-stop/tagged-css-modules/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243885889,"owners_count":20363644,"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-modules","template-literals"],"created_at":"2024-09-29T16:04:59.478Z","updated_at":"2026-01-03T14:07:11.024Z","avatar_url":"https://github.com/goto-bus-stop.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tagged-css-modules\n\nUse CSS Modules inline in tagged template strings. \n\n\u003e (Early experimental/wip)\n\n## Example\n\n```js\nconst html = require('nanohtml')\nconst css = require('tagged-css-modules')\n\nconst styles = css`\n  :global(body) {\n    background: #1b1b1b;\n  }\n\n  .header {\n    background: red;\n    padding: 20px;\n  }\n\n  .headerText {\n    color: yellow;\n  }\n`\n\ndocument.body.appendChild(html`\n  \u003cdiv class=\"${styles.header}\"\u003e\n    \u003ch1 class=\"${styles.headerText}\"\u003e\u003c/h1\u003e\n  \u003c/div\u003e\n`)\n```\n\n## Installation\n\nUsing npm:\n\n```bash\nnpm install --save tagged-css-modules\n```\n\n## API\n\n### ``` const styles = css`` ```\n\nParse a tagged template string as a css module. Returns an object of names to\nmangled names:\n\n```json\n{\n  \"header\": \"__input_1_header\"\n}\n```\n\n## `composes:` and imports\n\nBecause `tagged-css-modules` runs in the browser, it can't load referenced CSS\nfiles from the filesystem like native css-modules. So, composing classnames from\ndifferent files is a little different. It uses style objects instead of file\nnames.\n\n```js\n// utilities.js\nmodule.exports = css`\n  .centerContents {\n    display: flex;\n    justify-content: center;\n    align-items: center;\n  }\n`\n```\n\n```js\nconst utilities = require('./utilities')\nconst styles = css`\n  .header {\n    composes: centerContents from ${utilities};\n    font: 150% Open Sans;\n  }\n`\n```\n\nThe classnames used for composition are concatenated at runtime.\n\n## Babel\n\n`tagged-css-modules` uses postcss to transform your css at runtime. When\nbundling your app for production, that's a lot of code to include just for CSS.\nInstead, you can use the Babel plugin to transform your css ahead of time, and\nonly include a ~1kb runtime.\n\n```js\n// .babelrc\n{\n  \"plugins\": [\n    \"tagged-css-modules/babel\"\n  ]\n}\n```\n\n**Input**\n\n```js\n// utilities.js\nconst css = require('tagged-css-modules')\nmodule.exports = css`\n  .centerContents {\n    display: flex;\n    justify-content: center;\n    align-items: center;\n  }\n`\n```\n\n```js\n// index.js\nconst css = require('tagged-css-modules')\nconst utilities = require('./utilities')\nconst styles = css`\n  .header {\n    composes: centerContents from ${utilities};\n    font: 150% Open Sans;\n  }\n`\n```\n\n**Output**\n\n```js\n// utilities.js\nconst css = require('tagged-css-modules/runtime');\nmodule.exports = (css.insert('\\n  .centerContents_0 {\\n    display: flex;\\n    justify-content: center;\\n    align-items: center;\\n  }\\n'), {\n  'centerContents': 'centerContents_0'\n});\n```\n\n```js\n// index.js\nconst css = require('tagged-css-modules/runtime');\nconst utilities = require('./utilities');\nconst styles = (css.insert('.header_0 {\\n    font: 150% Open Sans;\\n  }\\n'), {\n  'header': ['header_0', utilities.centerContents].join(' ')\n});\n```\n\n## License\n\n[ISC](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Ftagged-css-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoto-bus-stop%2Ftagged-css-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoto-bus-stop%2Ftagged-css-modules/lists"}