{"id":18303579,"url":"https://github.com/kingvid-chan/css-id-replace-loader","last_synced_at":"2026-05-05T12:31:51.512Z","repository":{"id":90309713,"uuid":"77685643","full_name":"kingvid-chan/css-id-replace-loader","owner":"kingvid-chan","description":"Another solution to CSS Module","archived":false,"fork":false,"pushed_at":"2017-03-23T14:47:06.000Z","size":348,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-30T21:52:00.784Z","etag":null,"topics":["css-modules","loader","webpack"],"latest_commit_sha":null,"homepage":"","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/kingvid-chan.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-12-30T12:43:05.000Z","updated_at":"2018-01-16T11:13:49.000Z","dependencies_parsed_at":null,"dependency_job_id":"2eeb38bc-759b-487a-b660-83dc987b41a9","html_url":"https://github.com/kingvid-chan/css-id-replace-loader","commit_stats":{"total_commits":6,"total_committers":2,"mean_commits":3.0,"dds":"0.33333333333333337","last_synced_commit":"09fa28a0b460ad1fb35f86d022caef25a2b4c882"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kingvid-chan/css-id-replace-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingvid-chan%2Fcss-id-replace-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingvid-chan%2Fcss-id-replace-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingvid-chan%2Fcss-id-replace-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingvid-chan%2Fcss-id-replace-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kingvid-chan","download_url":"https://codeload.github.com/kingvid-chan/css-id-replace-loader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingvid-chan%2Fcss-id-replace-loader/sbom","scorecard":{"id":560879,"data":{"date":"2025-08-11","repo":{"name":"github.com/kingvid-chan/css-id-replace-loader","commit":"09fa28a0b460ad1fb35f86d022caef25a2b4c882"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 0/6 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-20T13:38:17.853Z","repository_id":90309713,"created_at":"2025-08-20T13:38:17.853Z","updated_at":"2025-08-20T13:38:17.853Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32649526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-05T11:29:49.557Z","status":"ssl_error","status_checked_at":"2026-05-05T11:29:48.587Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["css-modules","loader","webpack"],"created_at":"2024-11-05T15:26:07.142Z","updated_at":"2026-05-05T12:31:51.488Z","avatar_url":"https://github.com/kingvid-chan.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"200\" height=\"200\"\n    src=\"https://worldvectorlogo.com/logos/html5.svg\"\u003e\n  \u003ca href=\"https://github.com/webpack/webpack\"\u003e\n    \u003cimg width=\"200\" height=\"200\" vspace=\"\" hspace=\"25\"\n      src=\"https://worldvectorlogo.com/logos/webpack.svg\"\u003e\n  \u003c/a\u003e\n  \u003ch1\u003eCss-Id-Replace Loader\u003c/h1\u003e\n  \u003cp\u003eAnother solution to CSS Module\u003cp\u003e\n\u003c/div\u003e\n\n\u003ch2 align=\"center\"\u003e安装\u003c/h2\u003e\n\n```bash\nnpm i -D cssidreplace-loader\n```\n\n\u003ch2 align=\"center\"\u003e前言\u003c/h2\u003e\n\n讲一下我司的另一种css模块化解决方案，给每个模块自定义一个css key，比如说`customHeader`，在该模块的所有css样式签名都套上.customHeader  \ne.g.这是模块html文件\n```html\n\u003cheader\u003e\n\t\u003ch1\u003ethis is header\u003c/h1\u003e\n\t\u003cp\u003ecss模块化解决方案\u003c/p\u003e\n\u003c/header\u003e\n```\n以下是该模块css代码\n```css\n.customHeader header{\n\twidth: 990px;\n\tmargin: 10px auto;\n}\n.customHeader h1{\n\tfont-style: italic;\n}\n.customHeader p{\n\tcolor: #ccc;\n}\n```\nwebpack打包的时候给该模块css key添加一个随机唯一的数值生成最终的cssId，e.g.customHeader-123456，生成最终文件代码如下：\n```html\n\u003cstyle type=\"text/css\"\u003e\n.customHeader-123456 header{\n\twidth: 990px;\n\tmargin: 10px auto;\n}\n.customHeader-123456 h1{\n\tfont-style: italic;\n}\n.customHeader-123456 p{\n\tcolor: #ccc;\n}\n\u003c/style\u003e\n\u003cdiv class=\"customHeader-123456\"\u003e\n\t\u003cheader\u003e\n\t\t\u003ch1\u003ethis is header\u003c/h1\u003e\n\t\t\u003cp\u003ecss模块化解决方案\u003c/p\u003e\n\t\u003c/header\u003e\n\u003c/div\u003e\n```\n\n\u003ch2 align=\"center\"\u003e用法\u003c/h2\u003e\n\ncssidreplace-loader的作用就是在webpack打包时把css代码中的css key替换成css Id（即是把customHeader替换成customHeader-123456）。  \n可配置参数有两个：`regex`和`sub`，`regex`指待替换css key，`sub`指css Id，在webpack配置文件中代码如下：\n```js\n{\n  test: /\\.css$/,\n  use: [\n\t{\n\t  loader: \"style-loader\"\n\t},\n\t{\n\t  loader: \"css-loader\"\n\t},\n\t{\n\t  loader: 'cssidreplace-loader',\n\t  options: {\n\t    regex: 'customHeader',\n\t    sub: 'customHeader-123456'\n\t  }\n\t}\n  ]\n}\n```\n每个模块的css Id都是不同的，咱们可以通过通过动态配置webpack给对应的模块替换上相应的css Id\n```js\n// 注意：默认模块名称跟模块文件夹名称是一致的\n// var modulesMap = [  // 举例，假设这个是所有模块的索引\n//     {\n//         name: 'header', // 模块名称\n//         cssKey: 'customHeader',\n//         cssId: 'customHeader-123456'\n//     },\n//     {\n//         name: 'footer',\n//         cssKey: 'customFooter',\n//         cssId: 'customFooter-323122'\n//     },\n// ];\nconst webpack = require('webpack');\nconst webpack_config = require('./webpack.config');\nconst webpackDevServer = require('webpack-dev-server');\nmodulesMap.forEach((module) =\u003e {\n  webpack_config.module.rules.unshift({\n    test: eval(\"/\\.css$/i\"),\n    include: eval(module.name),\n    use: [\n      \t{\n      \t  loader: \"style-loader\"\n      \t},\n      \t{\n      \t  loader: \"css-loader\"\n      \t},\n      \t{\n      \t  loader: 'cssidreplace-loader',\n      \t  options: {\n      \t    regex: module.cssKey,\n      \t    sub: module.cssId\n      \t  }\n      \t}\n    ]\n  });\n});\n//webpack dev server\nconst compiler = webpack(webpack_config);\nnew webpackDevServer(compiler, {\n  stats: {\n    colors: true,\n    chunks: false\n  },\n  noInfo: false,\n  proxy: {\n    '*': {\n      target: 'http://localhost:3000',\n    }\n  }\n}).listen(8080, function(){console.log('App (dev) is now running on port 8080!');});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingvid-chan%2Fcss-id-replace-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingvid-chan%2Fcss-id-replace-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingvid-chan%2Fcss-id-replace-loader/lists"}