{"id":18182927,"url":"https://github.com/rodrigotomees/astro-rename","last_synced_at":"2025-09-11T09:34:03.759Z","repository":{"id":170757418,"uuid":"646990986","full_name":"RodrigoTomeES/astro-rename","owner":"RodrigoTomeES","description":"Astro-Rename is an Astro integration that brings postcss-rename functionality to your Astro project without the need of configuration.","archived":false,"fork":false,"pushed_at":"2024-06-21T11:58:12.000Z","size":2949,"stargazers_count":20,"open_issues_count":4,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T01:44:18.199Z","etag":null,"topics":["astro","astro-integration","compress","css","postcss","postcss-rename","tailwind","tailwindcss","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/astro-rename","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RodrigoTomeES.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2023-05-29T20:20:02.000Z","updated_at":"2025-07-05T17:22:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"9e07936f-c4eb-4fe4-a4d4-d0662085f99c","html_url":"https://github.com/RodrigoTomeES/astro-rename","commit_stats":null,"previous_names":["rodrigotomees/astro-rename"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/RodrigoTomeES/astro-rename","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Fastro-rename","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Fastro-rename/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Fastro-rename/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Fastro-rename/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RodrigoTomeES","download_url":"https://codeload.github.com/RodrigoTomeES/astro-rename/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RodrigoTomeES%2Fastro-rename/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274609465,"owners_count":25316621,"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-11T02:00:13.660Z","response_time":74,"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":["astro","astro-integration","compress","css","postcss","postcss-rename","tailwind","tailwindcss","typescript"],"created_at":"2024-11-02T19:03:42.500Z","updated_at":"2025-09-11T09:34:03.697Z","avatar_url":"https://github.com/RodrigoTomeES.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# astro-rename\n\nAstro-Rename is an Astro integration that brings [postcss-rename](https://github.com/google/postcss-rename) functionality to your Astro project without the need for configuration.\n\n## Features\n\n- [x] Compress CSS classes\n- [ ] Compress CSS IDs\n- [ ] Compress CSS Variables\n- [x] Replace CSS classes in HTML, JS, and other files\n\n## Installation\n\n```bash\nnpm install --save-dev astro-rename\n\n# or\n\nyarn add --dev astro-rename\n```\n\n## Usage\n\nAdd the plugin to your Astro config file:\n\n```js\nimport rename from 'astro-rename';\n\nexport default defineConfig({\n  // It's important to set the output directory to \"static\" because it's the only method that will work with the current version of the plugin.\n  // If you don't set this, the plugin will throw an error.\n  output: 'static',\n  integrations: [rename()],\n});\n```\n\n## Options\n\nThe plugin is typed, allowing you to see the available options in your editor. Here's a list of them:\n\n````ts\ntype RenameOptions = {\n  rename?: {\n    /**\n     * The renaming strategy to use:\n     *  - \"none\": Don't change names at all. This is the default strategy.\n     * - \"debug\": Add an underscore at the end of each name. This is useful for keeping classes readable during debugging while still verifying that your templates and JavaScript aren't accidentally using non-renamed classes.\n     * - \"minimal\": Use the shortest possible names, in order of appearance: the first class is renamed to .a, the second to .b, and so on.\n     *\n     * This can also be a function that takes a CSS name (the full name in by-whole mode and the part in by-part mode) and returns its renamed value.\n     *\n     * @default 'minimal'\n     */\n    strategy?: 'none' | 'debug' | 'minimal' | ((string: any) =\u003e string);\n    /**\n     * Whether to rename in \"by-whole mode\" or \"by-part mode\".\n     * - \"whole\": Rename the entire name at once, so for example .tall-image might become .a. This is the default mode.\n     * - \"part\": Rename each hyphenated section of a name separately, so for example .tall-image might become .a-b.\n     *\n     * @default 'whole'\n     */\n    by?: 'whole' | 'part';\n    /**\n     * A string prefix to add before every renamed class. This applies even if strategy is set to none.\n     * In by-part mode, the prefix is applied to the entire class, but it isn't included in the output map.\n     *\n     * @default undefined\n     */\n    prefix?: string;\n    /**\n     * An array (or other Iterable) of names that shouldn't be renamed.\n     *\n     * @default undefined\n     */\n    except?: Iterable\u003cstring | RegExp\u003e;\n    /**\n     * A callback that's passed a map from original class names to their renamed equivalents, so that an HTML template or JS class references can also be renamed.\n     *\n     * In by-part mode, this contains separate entries for each part of a class name. It doesn't contain any names that weren't renamed because of except.\n     *\n     * @default undefined\n     */\n    outputMapCallback?(map: { [key: string]: string }): void;\n  };\n  /**\n   * The target file extensions to process.\n   *\n   * @default '[\"html\", \"js\"]''\n   */\n  targetExt?: string[];\n  /**\n   * A function that takes a CSS name (the full name in by-whole mode and the part in by-part mode) and returns a regular expression that matches that name.\n   * This is used to find references to the original class names in HTML templates and JS classes.\n   * The default is to match the name with word boundaries on either side, but you can change this to match only the start or end of the name, or to match more or less than a whole word.\n   *\n   * @default ```js\n   * (key: string) =\u003e `(:^|[^-\u0026;:_])(${key})(?![a-zA-Z0-9_-])(:$|[^-\u0026;:_\\./])`\n   * ```\n   */\n  matchClasses?: (key: string) =\u003e string;\n};\n````\n\n## Configuration with other plugins\n\nIf you're using other plugins that modify your CSS, you may need to adjust the order in which they are applied. For example:\n\n```ts\nimport tailwind from '@astrojs/tailwind';\nimport compress from 'astro-compress';\nimport critters from 'astro-critters';\nimport rename from 'astro-rename';\n\nexport default defineConfig({\n  output: 'static',\n  integrations: [\n    // First, run Tailwind to generate the CSS\n    tailwind(),\n    // Then, compress the class names\n    rename(),\n    // Finally, inline the critical CSS\n    critters(),\n    // And compress the CSS, HTML, JS... files\n    compress(),\n  ],\n});\n```\n\n## Example\n\nHere's an example of the plugin in action in my [awa-db](https://github.com/RodrigoTomeES/awa-db) project. The average size reduction of HTML files is around 50%.\n\n```bash\n┌─────────────────────────────────┬───────────────┬──────────┬─────────┬─────────┬─────────┐\n│                            File │ Original Size │ New Size │ Reduced │    Gzip │  Brotli │\n├─────────────────────────────────┼───────────────┼──────────┼─────────┼─────────┼─────────┤\n│                    1\\index.html │       20.7 kB │  9.94 kB │     52% │ 2.68 kB │ 2.21 kB │\n│                   10\\index.html │       20.6 kB │  9.81 kB │     52% │ 2.68 kB │ 2.21 kB │\n│                   11\\index.html │       20.7 kB │  9.91 kB │     52% │ 2.71 kB │ 2.22 kB │\n│                   12\\index.html │       20.6 kB │  9.82 kB │     52% │ 2.65 kB │ 2.18 kB │\n│                   13\\index.html │       20.6 kB │  9.84 kB │     52% │ 2.71 kB │ 2.22 kB │\n│                   14\\index.html │       20.5 kB │  9.78 kB │     52% │ 2.63 kB │ 2.15 kB │\n│                   15\\index.html │       20.7 kB │   9.9 kB │     52% │ 2.72 kB │ 2.27 kB │\n│                   16\\index.html │       20.7 kB │  9.98 kB │     51% │ 2.72 kB │ 2.24 kB │\n│                   17\\index.html │       20.7 kB │  9.92 kB │     52% │  2.7 kB │ 2.22 kB │\n│                   18\\index.html │       20.4 kB │  9.67 kB │     52% │ 2.54 kB │ 2.08 kB │\n│                   19\\index.html │       20.6 kB │  9.82 kB │     52% │ 2.63 kB │ 2.15 kB │\n│                    2\\index.html │       20.6 kB │   9.8 kB │     52% │  2.7 kB │  2.2 kB │\n│                   20\\index.html │       22.8 kB │    12 kB │     47% │ 3.72 kB │ 2.97 kB │\n│                   21\\index.html │       20.7 kB │  9.93 kB │     52% │ 2.79 kB │ 2.25 kB │\n│                   22\\index.html │         22 kB │  11.3 kB │     48% │ 3.48 kB │ 2.84 kB │\n│                   23\\index.html │       20.7 kB │  9.94 kB │     51% │ 2.52 kB │ 2.04 kB │\n│                   24\\index.html │       13.8 kB │  6.82 kB │     50% │ 2.21 kB │ 1.81 kB │\n│                    3\\index.html │       20.4 kB │  9.66 kB │     52% │  2.6 kB │ 2.16 kB │\n│                    4\\index.html │       20.5 kB │  9.72 kB │     52% │ 2.58 kB │ 2.12 kB │\n│                    5\\index.html │       20.3 kB │  9.54 kB │     53% │ 2.52 kB │ 2.09 kB │\n│                    6\\index.html │       20.5 kB │  9.75 kB │     52% │ 2.63 kB │ 2.17 kB │\n│                    7\\index.html │       20.3 kB │  9.58 kB │     52% │  2.6 kB │ 2.15 kB │\n│                    8\\index.html │       20.4 kB │  9.68 kB │     52% │ 2.62 kB │ 2.16 kB │\n│                    9\\index.html │       20.5 kB │  9.71 kB │     52% │ 2.64 kB │ 2.19 kB │\n│          artifacts\\1\\index.html │       17.9 kB │  8.98 kB │     49% │ 2.74 kB │ 2.19 kB │\n│            avatars\\1\\index.html │       20.4 kB │  9.68 kB │     52% │  2.6 kB │ 2.15 kB │\n│           avatars\\10\\index.html │       20.6 kB │   9.8 kB │     52% │ 2.69 kB │  2.2 kB │\n│           avatars\\11\\index.html │       20.5 kB │  9.71 kB │     52% │ 2.57 kB │ 2.12 kB │\n│           avatars\\12\\index.html │       20.7 kB │   9.9 kB │     52% │ 2.74 kB │ 2.25 kB │\n│           avatars\\13\\index.html │       20.7 kB │  9.89 kB │     52% │ 2.65 kB │ 2.18 kB │\n│           avatars\\14\\index.html │       20.5 kB │  9.77 kB │     52% │ 2.58 kB │ 2.12 kB │\n│           avatars\\15\\index.html │       20.4 kB │  9.62 kB │     52% │ 2.58 kB │ 2.13 kB │\n│           avatars\\16\\index.html │         16 kB │  7.77 kB │     51% │ 2.34 kB │ 1.92 kB │\n│            avatars\\2\\index.html │       20.5 kB │  9.78 kB │     52% │ 2.58 kB │ 2.12 kB │\n│            avatars\\3\\index.html │       20.3 kB │  9.52 kB │     53% │ 2.52 kB │ 2.08 kB │\n│            avatars\\4\\index.html │       20.5 kB │  9.71 kB │     52% │ 2.56 kB │ 2.12 kB │\n│            avatars\\5\\index.html │       20.4 kB │  9.64 kB │     52% │  2.6 kB │ 2.16 kB │\n│            avatars\\6\\index.html │       20.4 kB │  9.67 kB │     52% │ 2.63 kB │ 2.17 kB │\n│            avatars\\7\\index.html │       20.4 kB │  9.68 kB │     52% │ 2.62 kB │ 2.17 kB │\n│            avatars\\8\\index.html │       20.6 kB │  9.82 kB │     52% │ 2.62 kB │ 2.15 kB │\n│            avatars\\9\\index.html │       20.7 kB │  9.93 kB │     52% │ 2.67 kB │ 2.19 kB │\n│ badges-and-borders\\1\\index.html │       20.7 kB │  9.97 kB │     51% │ 2.69 kB │ 2.21 kB │\n│ badges-and-borders\\2\\index.html │       20.6 kB │  9.88 kB │     52% │ 2.68 kB │ 2.21 kB │\n│ badges-and-borders\\3\\index.html │       20.8 kB │  10.1 kB │     51% │ 2.76 kB │ 2.26 kB │\n│ badges-and-borders\\4\\index.html │       18.3 kB │  8.79 kB │     51% │ 2.46 kB │ 2.03 kB │\n│       dell-rewards\\1\\index.html │       20.7 kB │  9.98 kB │     51% │  2.7 kB │ 2.22 kB │\n│       dell-rewards\\2\\index.html │         21 kB │  10.2 kB │     51% │ 2.35 kB │ 1.89 kB │\n│         game-vault\\1\\index.html │       22.9 kB │  12.2 kB │     46% │ 3.76 kB │ 3.02 kB │\n│         game-vault\\2\\index.html │       11.6 kB │  6.47 kB │     44% │ 2.54 kB │ 2.05 kB │\n│                      index.html │       20.7 kB │  9.89 kB │     52% │ 2.66 kB │  2.2 kB │\n│            unknown\\1\\index.html │       20.6 kB │  9.81 kB │     52% │ 1.86 kB │ 1.48 kB │\n│           unknown\\10\\index.html │       19.9 kB │  9.14 kB │     54% │ 1.83 kB │ 1.44 kB │\n│           unknown\\11\\index.html │       20.1 kB │  9.36 kB │     53% │ 1.87 kB │ 1.47 kB │\n│           unknown\\12\\index.html │       19.8 kB │     9 kB │     54% │ 1.85 kB │ 1.45 kB │\n│           unknown\\13\\index.html │       19.7 kB │   8.9 kB │     54% │ 1.83 kB │ 1.45 kB │\n│            unknown\\2\\index.html │       20.5 kB │  9.77 kB │     52% │ 1.84 kB │ 1.46 kB │\n│            unknown\\3\\index.html │       19.7 kB │  8.92 kB │     54% │ 1.86 kB │ 1.48 kB │\n│            unknown\\4\\index.html │       19.6 kB │  8.84 kB │     54% │ 1.82 kB │ 1.44 kB │\n│            unknown\\5\\index.html │       19.6 kB │  8.84 kB │     54% │ 1.82 kB │ 1.44 kB │\n│            unknown\\6\\index.html │       19.6 kB │  8.84 kB │     54% │ 1.82 kB │ 1.44 kB │\n│            unknown\\7\\index.html │       19.6 kB │  8.84 kB │     54% │ 1.82 kB │ 1.45 kB │\n│            unknown\\8\\index.html │       19.7 kB │  8.92 kB │     54% │ 1.84 kB │ 1.45 kB │\n│            unknown\\9\\index.html │       19.8 kB │  9.07 kB │     54% │ 1.84 kB │ 1.45 kB │\n└─────────────────────────────────┴───────────────┴──────────┴─────────┴─────────┴─────────┘\n```\n\n## TODO\n\nHere's a list of tasks I plan to work on:\n\n- [ ] Fix error types\n- [ ] Add test coverage\n- [ ] Add support for IDs\n- [ ] Enable handling of multiple CSS files\n- [ ] Implement support for CSS variables\n- [ ] Include server-side rendering support\n- [ ] Move temporal files to a temporary directory instead of the root of the project\n- [ ] Improve stadistics of file size reduction\n- [ ] Publish the package in multiple registers\n  - [x] NPM\n  - [ ] Yarn\n  - [ ] PNPM\n  - [ ] GitHub\n- [x] Show size of the result files with gzip and brotli\n\n## Licence\n\nThe codebase of this project is distributed under the [GNU General Public License (GPL) version 3.0](LICENCE). However, it is important to note that certain resources utilized within the project may be subject to different licenses. It is recommended to review the specific licenses associated with each resource to ensure compliance with their respective terms and conditions.\n\n## Credits\n\nSpecial thanks to the following individuals and projects:\n\n- [postcss-rename](https://github.com/google/postcss-rename) by Google\n- [@JSC0DER](https://github.com/JSC0DER) for their assistance with the [initial idea](https://github.com/google/postcss-rename/discussions/44)\n- [@Gechu03](https://github.com/Gechu03) and [@sergiomalagon](https://github.com/sergiomalagon) for their assistance with the regular expressions to match the CSS selectors\n\n## Contributors\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003ctable\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://jakebolam.com\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/3534236?v=4?s=100\" width=\"100px;\" alt=\"Jake Bolam\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eJake Bolam\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#bug-jakebolam\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n      \u003ctd align=\"center\" valign=\"top\" width=\"14.28%\"\u003e\u003ca href=\"https://kenchandev.com\"\u003e\u003cimg src=\"https://avatars.githubusercontent.com/u/4991363?v=4?s=100\" width=\"100px;\" alt=\"Ken Chan\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eKen Chan\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"#bug-kenchandev\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003c!-- markdownlint-restore --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigotomees%2Fastro-rename","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigotomees%2Fastro-rename","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigotomees%2Fastro-rename/lists"}