├── .editorconfig ├── .gitattributes ├── .github └── workflows │ ├── codeql-analysis.yml │ └── test.yml ├── .gitignore ├── .npmignore ├── .prettierrc.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── codeGenHelper.ts ├── index.test.ts ├── index.ts ├── package-lock.json ├── package.json ├── renameHelper.ts ├── splitFiles.ts ├── tsconfig.json └── types.ts /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '16 19 * * 0' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'javascript' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 37 | # Learn more: 38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 39 | 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v2 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: 3 | push: 4 | pull_request: 5 | env: 6 | FORCE_COLOR: 2 7 | jobs: 8 | full: 9 | name: Node.js 15 Full 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout the repository 13 | uses: actions/checkout@v2 14 | - name: Install Node.js 15 | uses: actions/setup-node@v2 16 | with: 17 | node-version: 15 18 | - name: Install dependencies 19 | uses: bahmutov/npm-install@v1 20 | - name: Run tests 21 | run: yarn test 22 | short: 23 | runs-on: ubuntu-latest 24 | strategy: 25 | matrix: 26 | node-version: 27 | - 19 28 | - 18 29 | - 16 30 | - 14 31 | - 12 32 | - 10 33 | name: Node.js ${{ matrix.node-version }} Quick 34 | steps: 35 | - name: Checkout the repository 36 | uses: actions/checkout@v2 37 | - name: Install Node.js ${{ matrix.node-version }} 38 | uses: actions/setup-node@v2 39 | with: 40 | node-version: ${{ matrix.node-version }} 41 | - name: Install dependencies 42 | uses: bahmutov/npm-install@v1 43 | - name: Run unit tests 44 | run: npx jest 45 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | yarn-error.log 4 | npm-debug.log* 5 | 6 | coverage/ 7 | *.log 8 | .npm 9 | 10 | .DS_Store 11 | item.ts 12 | 13 | *.js 14 | *.d.ts 15 | 16 | build-history-folder* -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | yarn-error.log 2 | npm-debug.log 3 | package-lock.json 4 | yarn.lock 5 | 6 | *.test.js 7 | .travis.yml 8 | .editorconfig 9 | coverage/ 10 | .gitignore 11 | 12 | node_modules/ -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "none", 3 | "singleQuote": true, 4 | "semi": false 5 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | # V2.0.0 4 | 5 | - Exposed the function fixing problems with typescript in regards to [Pull Request by Kaciras](https://github.com/navanshu/postcss-variable-compress/pull/38) 6 | 7 | # V0.2.6 8 | 9 | - Updating issues 10 | - Update postcss 11 | 12 | # V0.2.5 13 | 14 | - Coverage 100%. 15 | 16 | # v0.2.0 17 | 18 | - Same api can be passed with function so you can check if a variable has to be ignored 19 | 20 | # v0.1.3 21 | 22 | - Fixed the scoping issue in the variable 23 | - Trying to circumvent the Regex. Can't remove it yet but have some checks before regex in place. 24 | - Plugin notifies postcss about if a Declaration has bee processed. 25 | 26 | # v0.1.2 27 | 28 | - Fixing readme 29 | 30 | # v0.1.1 31 | 32 | - Updated readme 33 | 34 | # v0.1.0 35 | 36 | - Initial release 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2021 Navanshu Rastogi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PostCSS Variable Compress ![npm](https://img.shields.io/npm/dy/postcss-variable-compress) ![GitHub branch checks state](https://img.shields.io/github/checks-status/navanshu/postcss-variable-compress/master) 2 | 3 | ## These are Docs of V4.0.0 which will be releasing soon, kindly refer to [Old Docs V3.0.0](https://github.com/navanshu/postcss-variable-compress/tree/87e6479e2f0a5959fd0a5c7536f4548fb950a8e2) 4 | 5 | [postcss-variable-compress] is a [PostCSS] plugin that minifies variable names and saves space in your CSS. It compresses CSS variables while ensuring that your stylesheet remains intact. Even if you have 1295 CSS variables, their names will not exceed two characters. Get it from [NPM]. 6 | 7 | [postcss]: https://github.com/postcss/postcss 8 | [postcss-variable-compress]: https://github.com/navanshu/postcss-variable-compress 9 | [npm]: https://www.npmjs.com/package/postcss-variable-compress 10 | 11 | ```css 12 | :root { 13 | --first-color: #16f; 14 | --second-color: #ff7; 15 | } 16 | 17 | #firstParagraph { 18 | background-color: var(--first-color); 19 | color: var(--second-color); 20 | } 21 | 22 | #container { 23 | --first-color: #290; 24 | } 25 | 26 | ```css 27 | :root { 28 | --0: #16f; 29 | --1: #ff7; 30 | } 31 | 32 | #firstParagraph { 33 | background-color: var(--0); 34 | color: var(--1); 35 | } 36 | 37 | #container { 38 | --0: #290; 39 | } 40 | ``` 41 | 42 | Usage 43 | Step 1: Install the plugin: 44 | 45 | ```sh 46 | npm install --save-dev postcss postcss-variable-compress 47 | ``` 48 | 49 | Step 2: Check your project for an existing PostCSS config: postcss.config.js in the project root, "postcss" section in package.json, or postcss in the bundle config. 50 | 51 | If you do not use PostCSS, add it according to the official docs and configure this plugin accordingly. 52 | 53 | Step 3: Add the plugin at the end of the plugins list: 54 | 55 | ```diff 56 | module.exports = { 57 | plugins: [ 58 | require('cssnano'), 59 | + require('postcss-variable-compress') 60 | ] 61 | } 62 | 63 | ``` 64 | ## Options 65 | 66 | The postcss-variable-compress function accepts the following options: 67 | 68 | * `preserveVariables` (optional): An array of variable names or skip functions to preserve from compression. 69 | 70 | * Variable names: Provide the names of variables as strings that you want to preserve. For example: `['color-red', 'font-size']`. 71 | 72 | * Skip functions: Provide skip functions that take a variable name as a parameter and return true to skip the variable, or false/undefined to process it. For example: 73 | 74 | ```javascript 75 | function skipFunction(variableName) { 76 | return variableName.startsWith('skip-'); 77 | } 78 | ``` 79 | 80 | * `history` (optional): When true is provided, changes are kept the same in subsequent builds. When a string path is provided, the list of variables will remain the same across builds, stored in the specified file. 81 | 82 | ### Example Usage 83 | 84 | ```javascript 85 | module.exports = { 86 | plugins: [ 87 | require('cssnano'), 88 | require('postcss-variable-compress')( 89 | // Pass CSS variables to avoid compression 90 | 'light', 'dark', 'font', 'vh', 'r' // Unprefixed 91 | // or 92 | '--height', '--font' // Prefixed 93 | // or pass in as many functions as you want 94 | // They take a single parameter, which is the name of the CSS variable 95 | // You can perform checks on the name and 96 | // return true if you want it to be skipped 97 | // For example: 98 | (name) => name.includes('skip') // Prefixed CSS variable example: --height 99 | // Avoid using regex if possible, as they can be less efficient 100 | ) 101 | ] 102 | } 103 | ``` 104 | 105 | * The history option in postcss-variable-compress allows you to maintain a consistent list of variables across different builds by storing them in a JSON file. When a string path is provided for the history option, the plugin will load the build history from the specified file and ensure that the variables remain the same in subsequent builds. 106 | 107 | * This feature is particularly useful when working in a team or using version control systems like Git. By storing the variables in a file, you can track changes to the variables over time and easily share the list of variables with your team members. 108 | 109 | ### To utilize the history / same variables accross builds effectively, follow these steps: 110 | 111 | 1. Specify the path where you want to store the build history JSON file. For example, you can use a file path like "buildHistory/postcssVariableCompress.json". 112 | 113 | 2. Include the path as the value for the history option when configuring the postcss-variable-compress plugin in your PostCSS setup. 114 | 115 | ```javascript 116 | module.exports = { 117 | plugins: [ 118 | require('postcss-variable-compress')( 119 | // Other options... 120 | { 121 | history: 'buildHistory/postcssVariableCompress.json', 122 | } 123 | ), 124 | ], 125 | }; 126 | ``` 127 | 128 | 3. Make sure to create the directory specified in the history option before running the PostCSS build. For example, create the buildHistory directory. 129 | 130 | 4. Add the build history JSON file to your version control system (e.g., Git) to track changes over time. 131 | 132 | __Note: It's a good practice to add the build history file to the .gitignore file or any other relevant ignore file to exclude it from being formatted by tools like Prettier. This ensures that the file remains readable and understandable in its Pretty format.__ 133 | 134 | By utilizing the history option and storing the variables in a JSON file, you can maintain consistency in your CSS variable names across builds, track changes to the variables over time, and collaborate effectively with your team members. 135 | 136 | [official docs]: https://github.com/postcss/postcss#usage 137 | -------------------------------------------------------------------------------- /codeGenHelper.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/navanshu/postcss-variable-compress/0bba6853f4b2ddb4a6fff9320a2eb4332632c988/codeGenHelper.ts -------------------------------------------------------------------------------- /index.test.ts: -------------------------------------------------------------------------------- 1 | import postcss, { Root } from "postcss"; 2 | import variableCompress, { VariableCompressParameters } from "./index"; 3 | 4 | async function run( 5 | input: string | { toString(): string } | Root, 6 | output: string, 7 | preserveVariables?: VariableCompressParameters[], 8 | history?: string | boolean 9 | ) { 10 | let result = await postcss([variableCompress(preserveVariables, history)]) 11 | .process(input, { 12 | from: undefined, 13 | }); 14 | 15 | expect(result.css).toEqual(output); 16 | expect(result.warnings()).toHaveLength(0); 17 | } 18 | 19 | it("Shorten css variables", async () => { 20 | await run( 21 | `:root { 22 | --first-color: #16f; 23 | --second-color: #ff7; 24 | --2: #000; 25 | } 26 | 27 | #firstParagraph { 28 | background-color: var(--first-color); 29 | color: var(--second-color); 30 | } 31 | 32 | #secondParagraph { 33 | background-color: var(--second-color); 34 | color: var(--first-color); 35 | } 36 | 37 | #container { 38 | --first-color: #290; 39 | } 40 | 41 | #thirdParagraph { 42 | background-color: var(--first-color); 43 | color: var(--second-color); 44 | } 45 | 46 | .section-title { 47 | color: var(--primary-color, var(--black, #222)); 48 | } 49 | 50 | code { 51 | --5: #555; 52 | }`, 53 | `:root { 54 | --0: #16f; 55 | --1: #ff7; 56 | --2: #000; 57 | } 58 | 59 | #firstParagraph { 60 | background-color: var(--0); 61 | color: var(--1); 62 | } 63 | 64 | #secondParagraph { 65 | background-color: var(--1); 66 | color: var(--0); 67 | } 68 | 69 | #container { 70 | --0: #290; 71 | } 72 | 73 | #thirdParagraph { 74 | background-color: var(--0); 75 | color: var(--1); 76 | } 77 | 78 | .section-title { 79 | color: var(--primary-color, var(--3, #222)); 80 | } 81 | 82 | code { 83 | --5: #555; 84 | }`, 85 | [ 86 | "--primary-color", 87 | "2", 88 | (e: string | string[]) => e.includes("special"), 89 | (e: string) => e === "--5", 90 | ] 91 | ); 92 | }); 93 | 94 | it("Support reloading. Now the plugin will reset mapped variables", 95 | async () => { 96 | await run( 97 | `:root{--first-color: #16f;--second-color: #ff7;}`, 98 | `:root{--0: #16f;--1: #ff7;}`, 99 | [], 100 | "./build-history-folder" 101 | ); 102 | await run( 103 | `:root{--second-color: #ff7;--first-color: #16f;}`, 104 | `:root{--1: #ff7;--0: #16f;}`, 105 | [], 106 | "./build-history-folder" 107 | ); 108 | }); -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import { SkipFunction, VariableCompressParameters, BuildHistory } from './types' 2 | export * from './types' 3 | import fs from 'fs' 4 | import path from 'path' 5 | 6 | const postcssPlugin = 'postcss-variable-compress' 7 | const buildHistoryFileName = 'postcssVariableCompress.json' 8 | 9 | let renamedVariables = new Set() 10 | let pureSkips = new Set() 11 | let functionBasedSkips: SkipFunction[] = [] 12 | let cssVariablesMap = new Map() 13 | 14 | function scriptCheck(val: string): boolean { 15 | return functionBasedSkips.some((skipFunc) => skipFunc(val)) 16 | } 17 | 18 | function shouldRun(val: string): boolean { 19 | return !renamedVariables.has(val) && !scriptCheck(val) 20 | } 21 | 22 | function getReplacementVariable() { 23 | 24 | } 25 | 26 | function increase(): void { 27 | let counter = cssVariablesMap.size 28 | let temp = counter.toString(36) 29 | 30 | while (pureSkips.has(temp)) { 31 | counter++ 32 | temp = counter.toString(36) 33 | } 34 | } 35 | 36 | function replacer(match: string): string { 37 | if (!shouldRun(match)) return match 38 | 39 | let exist = cssVariablesMap.get(match) 40 | if (!exist) { 41 | exist = '--' + cssVariablesMap.size.toString(36) 42 | increase() 43 | cssVariablesMap.set(match, exist) 44 | renamedVariables.add(exist) 45 | } 46 | 47 | return exist 48 | } 49 | 50 | function map(declaration: import('postcss').Declaration): void { 51 | const prop = declaration.prop 52 | if (prop && declaration.variable && shouldRun(prop)) { 53 | const old = prop 54 | let exist = cssVariablesMap.get(old) 55 | if (!exist) { 56 | exist = '--' + cssVariablesMap.size.toString(36) 57 | increase() 58 | cssVariablesMap.set(old, exist) 59 | renamedVariables.add(exist) 60 | } 61 | declaration.prop = exist 62 | } 63 | 64 | let value = declaration.value 65 | if ( 66 | value && 67 | value.includes('var(') && 68 | value.includes('--') && 69 | value.length <= 1000 70 | ) { 71 | value = value.replace(/--[\w-_]{1,1000}/g, replacer) 72 | declaration.value = value 73 | } 74 | 75 | // @ts-ignore 76 | declaration.processed = true 77 | } 78 | 79 | function loadBuildHistory(historyPath: string): void { 80 | try { 81 | let stats = fs.statSync(historyPath) 82 | if (stats.isDirectory()) { 83 | historyPath = path.join(historyPath, buildHistoryFileName) 84 | } 85 | 86 | try { 87 | stats = fs.statSync(historyPath) 88 | cssVariablesMap.clear() 89 | const fileData = fs.readFileSync(historyPath, 'utf8') 90 | const buildHistory: BuildHistory = JSON.parse(fileData) 91 | 92 | buildHistory.variables 93 | .filter((item) => Boolean(Array.isArray(item) && item.length === 2)) 94 | .forEach(([a, b]) => { 95 | cssVariablesMap.set(a, b) 96 | }) 97 | } catch (error) { 98 | fs.writeFileSync( 99 | historyPath, 100 | JSON.stringify( 101 | { 102 | variables: [] 103 | }, 104 | null, 105 | 2 106 | ), 107 | 'utf8' 108 | ) 109 | } 110 | } catch (error) { 111 | console.error('Failed to load build history:', error) 112 | } 113 | } 114 | async function saveBuildHistory(historyPath: string): Promise { 115 | try { 116 | const stats = await fs.promises.stat(historyPath) 117 | if (stats.isDirectory()) { 118 | historyPath = path.join(historyPath, buildHistoryFileName) 119 | } 120 | 121 | const buildHistory: BuildHistory = { 122 | variables: [...cssVariablesMap.entries()] 123 | } 124 | const jsonData = JSON.stringify(buildHistory, null, 2) 125 | 126 | await fs.promises.writeFile(historyPath, jsonData, 'utf8') 127 | } catch (error) { 128 | console.error('Failed to save build history:', error) 129 | } 130 | } 131 | 132 | /** 133 | * This is necessary as if the 134 | */ 135 | let lastHistory: string | boolean | undefined 136 | let runs = 0 137 | 138 | /** 139 | * 140 | * @param preserveVariables Provides facility to preserver the variables from being changed 141 | * @param history When true is provided changes are kept same in the build 142 | * @param history When a path is provided Keeps the list of variables same accross build at the cost of storing variables in a file 143 | * @returns 144 | */ 145 | function variableCompress( 146 | preserveVariables?: VariableCompressParameters[], 147 | history?: string | boolean 148 | ): any { 149 | let firstRun = runs === 0 150 | 151 | if ( 152 | !(history === true || typeof history === 'string') || 153 | (!firstRun && lastHistory !== history) 154 | ) { 155 | renamedVariables = new Set() 156 | pureSkips = new Set() 157 | functionBasedSkips = [] 158 | cssVariablesMap.clear() 159 | } 160 | 161 | runs++ 162 | 163 | if (typeof history === 'string') { 164 | loadBuildHistory(history) 165 | } 166 | 167 | preserveVariables?.forEach((param) => { 168 | if (typeof param === 'string') { 169 | let name = param 170 | let cssName = param 171 | 172 | if (param.slice(0, 2) === '--') { 173 | name = param.slice(2) 174 | } else { 175 | cssName = '--' + param 176 | } 177 | 178 | pureSkips.add(name) 179 | cssVariablesMap.set(cssName, cssName) 180 | } else { 181 | functionBasedSkips.push(param) 182 | } 183 | }) 184 | 185 | increase() 186 | 187 | return { 188 | postcssPlugin, 189 | Declaration: { 190 | '*': map 191 | }, 192 | async OnceExit() { 193 | if (typeof history === 'string') { 194 | await saveBuildHistory(history) 195 | } 196 | return true 197 | } 198 | } 199 | } 200 | 201 | module.exports = variableCompress 202 | module.exports.postcss = true 203 | export default variableCompress 204 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "postcss-variable-compress", 3 | "version": "4.0.0", 4 | "description": "PostCSS plugin cleans up the variable names and saves space. It can will reduce your css variable to smaller variables", 5 | "keywords": [ 6 | "postcss", 7 | "css", 8 | "postcss-plugin", 9 | "minify", 10 | "compress", 11 | "cssnano", 12 | "css-variables", 13 | "clean-css", 14 | "shrik-css", 15 | "vite", 16 | "nextjs" 17 | ], 18 | "scripts": { 19 | "test": "jest --coverage && eslint .", 20 | "tsc": "tsc --project tsconfig.json --watch" 21 | }, 22 | "author": "Navanshu Rastogi ", 23 | "license": "MIT", 24 | "repository": "navanshu/postcss-variable-compress", 25 | "engines": { 26 | "node": ">=10.0.0" 27 | }, 28 | "peerDependencies": { 29 | "postcss": "^8.2.8" 30 | }, 31 | "devDependencies": { 32 | "@types/jest": "^29.5.1", 33 | "@types/mocha": "^10.0.1", 34 | "clean-publish": "^4.0.0", 35 | "eslint": "^8.0.1", 36 | "eslint-plugin-jest": "^27.0.4", 37 | "jest": "^29.0.3", 38 | "lint-staged": "^13.0.3", 39 | "postcss": "^8.4.24", 40 | "simple-git-hooks": "^2.0.2", 41 | "ts-jest": "^29.1.0", 42 | "typescript": "^4.3.5" 43 | }, 44 | "simple-git-hooks": { 45 | "pre-commit": "npx lint-staged" 46 | }, 47 | "lint-staged": { 48 | "*.js": "eslint --fix" 49 | }, 50 | "eslintConfig": { 51 | "parserOptions": { 52 | "ecmaVersion": 2017 53 | }, 54 | "env": { 55 | "node": true, 56 | "es6": true 57 | }, 58 | "extends": [ 59 | "eslint:recommended", 60 | "plugin:jest/recommended" 61 | ], 62 | "rules": { 63 | "jest/expect-expect": "off" 64 | } 65 | }, 66 | "jest": { 67 | "preset": "ts-jest", 68 | "testEnvironment": "node", 69 | "coverageThreshold": { 70 | "global": { 71 | "statements": 100 72 | } 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /renameHelper.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/navanshu/postcss-variable-compress/0bba6853f4b2ddb4a6fff9320a2eb4332632c988/renameHelper.ts -------------------------------------------------------------------------------- /splitFiles.ts: -------------------------------------------------------------------------------- 1 | import variableCompress, { VariableCompressParameters } from './' 2 | export * from './types' 3 | 4 | module.exports = variableCompress; 5 | module.exports.postcss = true; 6 | export default variableCompress; -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2016", 4 | "module": "CommonJS", 5 | "declaration": true, 6 | "declarationMap": false, 7 | "sourceMap": false, 8 | "removeComments": false, 9 | "strict": true, 10 | "moduleResolution": "node", 11 | "esModuleInterop": true, 12 | "inlineSourceMap": false, 13 | "inlineSources": false, 14 | "skipLibCheck": true, 15 | "forceConsistentCasingInFileNames": true 16 | }, 17 | "include": [ 18 | "./" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /types.ts: -------------------------------------------------------------------------------- 1 | export type SkipFunction = (variableName: string) => boolean | undefined; 2 | export type VariableCompressParameters = SkipFunction | string; 3 | export interface BuildHistory { 4 | variables: [string,string][]; 5 | } 6 | --------------------------------------------------------------------------------