{"id":17937799,"url":"https://github.com/xobotyi/css-loader-incremental-ident","last_synced_at":"2025-03-24T08:33:53.655Z","repository":{"id":37186563,"uuid":"374905934","full_name":"xobotyi/css-loader-incremental-ident","owner":"xobotyi","description":"Incremental classnames generator for webpack`s css-loader","archived":false,"fork":false,"pushed_at":"2023-03-06T03:43:39.000Z","size":2188,"stargazers_count":4,"open_issues_count":16,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-29T13:22:13.287Z","etag":null,"topics":["classnames","css","css-loader","ident","incremental","minify","module","webpack"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/xobotyi.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":"2021-06-08T06:31:08.000Z","updated_at":"2023-07-11T13:10:21.000Z","dependencies_parsed_at":"2023-02-18T10:45:26.222Z","dependency_job_id":null,"html_url":"https://github.com/xobotyi/css-loader-incremental-ident","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xobotyi%2Fcss-loader-incremental-ident","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xobotyi%2Fcss-loader-incremental-ident/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xobotyi%2Fcss-loader-incremental-ident/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xobotyi%2Fcss-loader-incremental-ident/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xobotyi","download_url":"https://codeload.github.com/xobotyi/css-loader-incremental-ident/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221949901,"owners_count":16906485,"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":["classnames","css","css-loader","ident","incremental","minify","module","webpack"],"created_at":"2024-10-28T23:07:50.994Z","updated_at":"2024-10-28T23:07:51.536Z","avatar_url":"https://github.com/xobotyi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# css-loader-incremental-ident\n\n[![NPM Version](https://flat.badgen.net/npm/v/css-loader-incremental-ident)](https://www.npmjs.com/package/css-loader-incremental-ident)\n[![NPM Downloads](https://flat.badgen.net/npm/dm/css-loader-incremental-ident)](https://www.npmjs.com/package/css-loader-incremental-ident)\n[![NPM Dependents](https://flat.badgen.net/npm/dependents/css-loader-incremental-ident)](https://www.npmjs.com/package/css-loader-incremental-ident)\n[![Build](https://flat.badgen.net/github/checks/xobotyi/css-loader-incremental-ident)](https://github.com/xobotyi/css-loader-incremental-ident/actions)\n[![Coverage](https://flat.badgen.net/codecov/c/github/xobotyi/css-loader-incremental-ident)](https://app.codecov.io/gh/xobotyi/css-loader-incremental-ident)\n[![Types](https://flat.badgen.net/npm/types/css-loader-incremental-ident)](https://www.npmjs.com/package/css-loader-incremental-ident)\n\n\u003c/div\u003e\n\n---\n\nWebpack `css-loader`'s `getLocalIdent` implementation that will shrink your css-modules classnames\nto the smallest possible size.\n\n![example](./.github/img-example.jpg)\n\n## Why\n\nBy default, `css-loader` generates quite long classnames, you can shorten them for production,\nsetting `localIdentName` option to `[hash:base64:5]`, but this approach contains theoretical\ncollisions.  \nYes, it is hard to imagine css with `1 073 741 824` classnames, but the _chance_ is way beyond\ntolerable for me.\n\nProvided implementation is absolutely collision-safe, as each processed classname will have its own\nunique name.\n\n## Install\n\n```shell\nnpm i -D css-loader-incremental-ident\n# or\nyarn add -D css-loader-incremental-ident\n```\n\n## Configure\n\n```js\nconst { createLocalIdentGetter } = require(\"css-loader-incremental-ident\");\n\nmodule.exports = {\n  module: {\n    rules: [\n      {\n        // config for css modules\n        test: /\\.scss$/,\n        use: [\n          {\n            loader: MiniCssExtractPlugin.loader,\n          },\n          {\n            loader: \"css-loader\",\n            options: {\n              importLoaders: 3,\n              modules: {\n                localIdentName: \"[path][name]__[local]\",\n                getLocalIdent: createLocalIdentGetter({ bypass: !isProduction }),\n              },\n              sourceMap: !isProduction,\n            },\n          },\n          \"sass-loader\",\n        ],\n        include: /\\.module\\.scss$/,\n      },\n    ],\n  },\n};\n```\n\nBelow config uses classnames mangling for production build only, development build uses long\nclassnames for the sake of classnames obviousity.\n\n### Options\n\n```js\ncreateLocalIdentGetter(options);\n```\n\n**options.alphabet**\n\n- Type: `string`\n- Default: `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`\n\nAlphabet that is used for classnames generation. `-` and `_` characters are omitted as they mostly\nused as separators, but you can add them to alphabet manually.\n\n**options.bypass**\n\n- Type: `boolean`\n- Default: `false`\n\nBypass classname mangling, useful for separation between development and production builds. In case\nthis option set to `true`, `createLocalIdentGetter` will return `undefined` instead of function,\nthis will force `css-loader` to use default getter.\n\n**options.prefix**\n\n- Type: `string`\n- Default: `\"\"`\n\nCharacter to prepend to each classname.\n\n**options.suffix**\n\n- Type: `string`\n- Default: `\"\"`\n\nCharacter to append to each classname.\n\n**options.localIdentSeparator**\n\n- Type: `string`\n- Default: `_`\n\nGenerated classname consist of two parts `[resoirceId]{localIdentSeparator}[localId]`.\n`[resoirceId]` is the file id where classname takes its origin, it is unique over whole the\nbundle. `[localId]` is the classname id, it is unique within single resource.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxobotyi%2Fcss-loader-incremental-ident","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxobotyi%2Fcss-loader-incremental-ident","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxobotyi%2Fcss-loader-incremental-ident/lists"}