{"id":23419728,"url":"https://github.com/moshang-ax/postcss-vars-process","last_synced_at":"2026-05-20T14:34:19.324Z","repository":{"id":35079360,"uuid":"203756980","full_name":"moshang-ax/postcss-vars-process","owner":"moshang-ax","description":"PostCSS plugin to extract and replace variables from css, support legal custom format variables","archived":false,"fork":false,"pushed_at":"2023-01-05T22:00:19.000Z","size":803,"stargazers_count":1,"open_issues_count":13,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T12:14:58.529Z","etag":null,"topics":["css-variables","extract","extract-values","postcss"],"latest_commit_sha":null,"homepage":null,"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/moshang-ax.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-08-22T09:07:03.000Z","updated_at":"2020-10-26T15:07:59.000Z","dependencies_parsed_at":"2023-01-15T13:24:05.313Z","dependency_job_id":null,"html_url":"https://github.com/moshang-ax/postcss-vars-process","commit_stats":null,"previous_names":["aras-ax/postcss-vars-process","moshang-xc/postcss-vars-process","moshang-ax/postcss-vars-process"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moshang-ax%2Fpostcss-vars-process","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moshang-ax%2Fpostcss-vars-process/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moshang-ax%2Fpostcss-vars-process/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moshang-ax%2Fpostcss-vars-process/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moshang-ax","download_url":"https://codeload.github.com/moshang-ax/postcss-vars-process/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008626,"owners_count":21032559,"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-variables","extract","extract-values","postcss"],"created_at":"2024-12-23T01:43:44.231Z","updated_at":"2026-05-20T14:34:19.292Z","avatar_url":"https://github.com/moshang-ax.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PostCSS Vars Process [![Build Status][ci-img]][ci]\n\n[PostCSS] plugin to extract and replace variables form css, support legal custom format variables. Extract variables array for secondary development or other use, and replace variables based on the given value.\n\n[PostCSS]: https://github.com/postcss/postcss\n[ci-img]:  https://travis-ci.org/moshang-xc/postcss-vars-process.svg\n[ci]:      https://travis-ci.org/moshang-xc/postcss-vars-process\n\ninput\n```css\n.foo {\n    font-size: $(size);\n    color: $(color);\n}\n```\n\n```js\n// variable.js\nmodule.exports = {\n    size: '12px',\n    color: '#fff'\n}\npostcss([ require('postcss-vars-process')({\n    values: './variable.js'\n})])\n```\n\noutput\n\n```css\n.foo {\n    font-size: 12px;\n    color: #fff;\n}\n```\n\n```js\n// extract variables\n['size', 'color']\n```\n\n## Usage\n\n```js\npostcss([ require('postcss-vars-process')(options) ])\n```\n\nSee [PostCSS] docs for examples for your environment.\n\n## Installation\n```js\nnpm install postcss-vars-process\n```\n\n## options\n\n```css\n.text {\n    font-size: $(fontSize);\n    color: $(color);\n    line-height: 1;\n    background: $(color) url('$(logo)');\n}\n.error {\n    color: $(errorColor|#f00);\n}\n```\nNote: without special instructions the following cases all uses this `CSS` template .\n\n### values\n\n- Type: `String`/`Object`\n- Default: `null`\n- Required: `false`\n- Description:  The Object corresponding to the variables in css, used to replace the variable in css，like scss\n\nWhen the value is `String`, only the file address of type `.js` or `.json` is accepted, otherwise `Object` is accepted as the value.\n\n ### pattern\n\n- Type: `RegExp`/`String`\n- Default: `/\\$\\(([^()]+)\\)/g`\n- Required: `false`\n- Description: Regular rules for matching variable templates\n\nUsed to match custom template expressions in CSS. If there is a capture group, the expression corresponding to `$1` by default, otherwise the whole matching expression is extracted. If there is no capture group, `splitKey` is ignored by default。\n\n```js\n// with capture group\npostcss([ require('postcss-vars-process')({\n    values: {\n        'fontSize': '14px',\n    \t'color': '#333',\n    \t'logo': './img/logo.png',\n        'errorColor': '#f10'\n    },\n    extract(variables){\n        // variables: ['fontSize', 'color', 'logo', 'errorColor|#f00']\n        // do something with variables\n    }\n})])\n\n// without capture group\npostcss([ require('postcss-vars-process')({\n    pattern: //\\$\\([^()]+\\)/g/,\n    values: {\n        '$(fontSize)': '14px',\n    \t'$(color)': '#333',\n    \t'$(logo)': './logo.png',\n    \t'$(errorColor|#f00)': '#999'\n    },\n    extract(variables){\n        // variables: ['$(fontSize)', '$(color)', '$(logo)', '$(errorColor|#f00)']\n        // do something with variables\n    }\n})])\n```\n\n### logType\n\n- Type: `String:\u003cwarn|error\u003e`\n- Default: `warn`\n- Required: `false`\n- Description: Message prompt when variables cannot be  resolved\n\nWhen a variable cannot be resolved, this specifies whether to throw an error or log a warning. In the case of a warning, the unknow variables will be replaced with an empty string.\n\n### splitKey\n\n- Type: `String`\n- Default: `|`\n- Required: `false`\n\nAll parameters are added directly after the variable via `splitKey`. The number of parameters is not limited.  It is suggested that this attribute be used in conjunction with [extract](#extract), and it is meaningless to use it alone.\n\nFor example:\n\n```css\n.test{\n     border-color: $(color|2|#f00);\n}\n// extract 'color|2|#f00', then split it with splitKey |\nvariable: color\nvalueType: 2 \ndefaultValue: #f00\n```\n\n\u003e The meaning of the parameters is completely defined by you.\n\n### extract\n\n- Type: `Function(Array[])`\n- Default: `null`\n- Required: `false`\n\nIf you need to process the variables, `extract` must be filled in and must be Function.\n\n```js\n// with capture group\npostcss([ require('postcss-vars-process')({\n    extract(variables){\n        // variables: ['fontSize', 'color', 'logo', 'errorColor|#f00']\n        let vars = {};\n        variables.forEach(item =\u003e {\n\t\t\titem = item.split('|');\n            vars[item[0]] = item[1] : '';\n        });\n        // export variables\n        fs.writeFile(path.join(__dirname, 'vars.json'), JSON.stringify(vars));\n    }\n})])\n\n// vars.json\n{\n    \"fontSize\": \"\",\n    \"color\": \"\",\n    \"logo\": \"\",\n    \"errorColor\": \"#f00\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoshang-ax%2Fpostcss-vars-process","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoshang-ax%2Fpostcss-vars-process","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoshang-ax%2Fpostcss-vars-process/lists"}