{"id":19164187,"url":"https://github.com/coobaha/postcss-variables-loader","last_synced_at":"2025-05-07T11:23:13.412Z","repository":{"id":47016954,"uuid":"71669848","full_name":"Coobaha/postcss-variables-loader","owner":"Coobaha","description":"Share variables between CSS and JS with Webpack + HMR","archived":false,"fork":false,"pushed_at":"2023-10-27T01:04:23.000Z","size":2515,"stargazers_count":18,"open_issues_count":4,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-19T22:01:30.609Z","etag":null,"topics":["css","cssnext","hmr","postcss","postcss-variables-loader","webpack"],"latest_commit_sha":null,"homepage":null,"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/Coobaha.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-22T22:47:21.000Z","updated_at":"2023-10-07T12:06:22.000Z","dependencies_parsed_at":"2024-06-18T20:11:49.248Z","dependency_job_id":null,"html_url":"https://github.com/Coobaha/postcss-variables-loader","commit_stats":{"total_commits":80,"total_committers":4,"mean_commits":20.0,"dds":0.5875,"last_synced_commit":"edfc42cb7f688f6c90c7b2d1636647d58058d5f8"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fpostcss-variables-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fpostcss-variables-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fpostcss-variables-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Coobaha%2Fpostcss-variables-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Coobaha","download_url":"https://codeload.github.com/Coobaha/postcss-variables-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252866507,"owners_count":21816477,"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","cssnext","hmr","postcss","postcss-variables-loader","webpack"],"created_at":"2024-11-09T09:19:18.311Z","updated_at":"2025-05-07T11:23:13.390Z","avatar_url":"https://github.com/Coobaha.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cbig\u003e\u003ch1 align=\"center\"\u003epostcss-variables-loader\u003c/h1\u003e\u003c/big\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://npmjs.org/package/postcss-variables-loader\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/postcss-variables-loader.svg\" alt=\"NPM Version\"\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"http://opensource.org/licenses/MIT\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/l/postcss-variables-loader.svg\" alt=\"License\"\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://github.com/Coobaha/postcss-variables-loader/issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/Coobaha/postcss-variables-loader.svg\" alt=\"Github Issues\"\u003e\n  \u003c/a\u003e\n\n\n  \u003ca href=\"https://travis-ci.org/Coobaha/postcss-variables-loader\"\u003e\n    \u003cimg src=\"https://img.shields.io/travis/Coobaha/postcss-variables-loader.svg\" alt=\"Travis Status\"\u003e\n  \u003c/a\u003e\n\n\n\n  \u003ca href=\"https://coveralls.io/github/Coobaha/postcss-variables-loader\"\u003e\n    \u003cimg src=\"https://img.shields.io/coveralls/Coobaha/postcss-variables-loader.svg\" alt=\"Coveralls\"\u003e\n  \u003c/a\u003e\n\n\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\u003cbig\u003e\nAllows you to share variables between CSS and JS with Webpack and HMR.\n\u003c/big\u003e\u003c/p\u003e\n\u003cbr\u003e\nThis loader transforms special CSS files to JS modules.\n\n* Shared variables between CSS and JS\n* HMR friendly, CSS changes are applied on the fly.\n\nTo be more JS friendly loader will:\n\n* strip `px` part from CSS px numbers\n* convert dashes-case to camelCase\n* check for runtime config mutations and access of missing keys (only in dev or es6 mode)\n\n## Usage\n\n```css\n/* variables.config.css */\n\n@custom-media --small-device (max-width: 480px))\n:root {\n  --primary-color: blue;\n  --gutter: 30px;\n}\n```\n\n```css\n/* component.css  */\n\n@import 'colors.config.css'\n\n.component {\n  color: var(--primary-color);\n  margin: 0 var(--gutter);\n}\n\n@media (--small-device) {\n  /* styles for small viewport */\n}\n\n```\n\n```js\n// component.js\nimport variables from 'colors.config.css';\n\nconsole.log(variables);\n/*\n  variables = {\n    primaryColor: 'blue';\n    gutter: 30;\n    smallDevice: '(max-width: 480px)'\n  }\n*/\n\ncomponent.style.color = variables.primaryColor;\n\nfunction add5ToGutter() {\n  return 5 + variables.gutter;\n}\n```\n\n\n## Install\n\n```sh\nyarn add --dev postcss-variables-loader\n```\n\n```sh\nnpm install --save-dev postcss-variables-loader\n```\n\n**NB**: You need to process CSS somehow (eg [postcss](https://github.com/postcss/postcss))\n and imports inside css (eg via [postcss-import](https://github.com/postcss/postcss-import))\n\n\n**Recommended webpack configuration**:\n`webpack.config.js` with babel-loader\n```\nrules: [\n  {\n    test: /\\.config.css$/,\n    loader: 'babel-loader!postcss-variables-loader'\n  },\n\n  // dont forget to exclude *.config.css from other css loaders\n  {\n    test: /\\.css$/,\n    exclude: /\\.config.css$/,\n    loader: 'css-loader!postcss-loader'\n  }\n]\n```\n\n## Options\n\nif `production.env.NODE_ENV === 'development'` it will try to wrap config inside `Proxy` in runtime.\nIt is used to guard from accidental mutations or accessing missing keys.\nIf you dont want this behaviour: pass `es5=1`:\n\n`loader: 'postcss-variables-loader?es5=1'`\n\n## License\n\n- **MIT** : http://opensource.org/licenses/MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoobaha%2Fpostcss-variables-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoobaha%2Fpostcss-variables-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoobaha%2Fpostcss-variables-loader/lists"}