{"id":16367614,"url":"https://github.com/alexmacarthur/css-by-js","last_synced_at":"2025-09-15T02:25:27.850Z","repository":{"id":48005307,"uuid":"165742139","full_name":"alexmacarthur/css-by-js","owner":"alexmacarthur","description":"Turn your CSS into JS that turns it into inline CSS.","archived":false,"fork":false,"pushed_at":"2022-12-10T16:41:30.000Z","size":448,"stargazers_count":10,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T11:47:01.940Z","etag":null,"topics":["cascading-style-sheets","css","css-in-js","front-end-development","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexmacarthur.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":"2019-01-14T22:00:18.000Z","updated_at":"2025-03-07T13:48:53.000Z","dependencies_parsed_at":"2023-01-26T09:31:15.139Z","dependency_job_id":null,"html_url":"https://github.com/alexmacarthur/css-by-js","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alexmacarthur/css-by-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fcss-by-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fcss-by-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fcss-by-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fcss-by-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexmacarthur","download_url":"https://codeload.github.com/alexmacarthur/css-by-js/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexmacarthur%2Fcss-by-js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275194031,"owners_count":25421442,"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","status":"online","status_checked_at":"2025-09-15T02:00:09.272Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cascading-style-sheets","css","css-in-js","front-end-development","javascript"],"created_at":"2024-10-11T02:50:23.288Z","updated_at":"2025-09-15T02:25:27.812Z","avatar_url":"https://github.com/alexmacarthur.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSS by JS\n\nThe next iteration of CSS-in-JS. Turn your CSS into JS that turns it into CSS.\n\n## Description\n\nThis a CLI tool that will turn a CSS file into JS, which will then apply the styles to the DOM when loaded in the browser. So, you write CSS, but you never load a single `*.css` file onto your page. It's left to JS, which is doing eveything else these days anyway.\n\nFor example, this CSS:\n\n```css\n:root {\n  --my-color: #1a1a1a;\n}\n\nbody,\nhtml {\n  font-family: \"Source Sans Pro\", sans-serif;\n  background: linear-gradient(45deg, #f5d9ff, #fefdff);\n  color: var(--my-color);\n}\n\nmain {\n  text-align: center;\n  max-width: 700px;\n  margin: 0 auto;\n}\n\nh1,\nh3 {\n  margin: 0;\n}\n```\n\nTurns into this, which is then passed to a `applyCSS` function:\n\n```javascript\n[\n  { name: \":root\", properties: [{ name: \"--my-color\", value: \"#1a1a1a\" }] },\n  {\n    name: \"body, html\",\n    properties: [\n      { name: \"font-family\", value: \"'Source Sans Pro', sans-serif\" },\n      { name: \"background\", value: \"linear-gradient(45deg, #f5d9ff, #fefdff)\" },\n      { name: \"color\", value: \"var(--my-color)\" }\n    ]\n  },\n  {\n    name: \"main\",\n    properties: [\n      { name: \"text-align\", value: \"center\" },\n      { name: \"max-width\", value: \"700px\" },\n      { name: \"margin\", value: \"0 auto\" }\n    ]\n  },\n  { name: \"h1, h3\", properties: [{ name: \"margin\", value: \"0\" }] }\n];\n```\n\nAnd when the output is loaded on your page, you get styles:\n\n```html\n\u003cscript src=\".output/css-by-js.js\"\u003e\u003c/script\u003e\n```\n\n![alt text](./assets/markup.jpg \"styles applied to DOM\")\n\n## Installation\n\n`npm install css-by-js`\n\n## Usage\n\nYou just need to pass in a reference to a CSS file, as well as location where the file will be outputted.\n\n`css-by-js --file=./assets/sample.css --output=./assets/output.js`\n\nA `--file` is required. If no `--output` is specified, a `css-by-js.js` file will be created in the current directory.\n\n## Support\n\nI can't imagine it works perfectly in every scenario, but I've designed the tool to handle simple element CSS rules (`div{}`), pseudo-elements, and even CSS custom properties. If you find an oddball out there, make file an issue or make a contribution.\n\n## Why would I use this?\n\nI'll leave that up to you.\n\n## License\n\nMIT © [Alex MacArthur](https://macarthur.me)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmacarthur%2Fcss-by-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexmacarthur%2Fcss-by-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexmacarthur%2Fcss-by-js/lists"}