{"id":13678092,"url":"https://github.com/rspack-contrib/rsbuild-plugin-typed-css-modules","last_synced_at":"2025-04-14T10:13:25.147Z","repository":{"id":248504552,"uuid":"828903408","full_name":"rspack-contrib/rsbuild-plugin-typed-css-modules","owner":"rspack-contrib","description":"An Rsbuild plugin to generate TypeScript declaration files for CSS Modules","archived":false,"fork":false,"pushed_at":"2025-04-01T03:55:16.000Z","size":150,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-14T10:13:20.286Z","etag":null,"topics":["rsbuild","rsbuild-plugin","rspack"],"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/rspack-contrib.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2024-07-15T11:06:37.000Z","updated_at":"2025-04-01T03:55:18.000Z","dependencies_parsed_at":"2024-11-09T06:18:18.019Z","dependency_job_id":"e9d63282-2ab7-4a7a-81c7-a14fe6e2fe57","html_url":"https://github.com/rspack-contrib/rsbuild-plugin-typed-css-modules","commit_stats":null,"previous_names":["rspack-contrib/rsbuild-plugin-typed-css-modules"],"tags_count":2,"template":false,"template_full_name":"rspack-contrib/rsbuild-plugin-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frsbuild-plugin-typed-css-modules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frsbuild-plugin-typed-css-modules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frsbuild-plugin-typed-css-modules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rspack-contrib%2Frsbuild-plugin-typed-css-modules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rspack-contrib","download_url":"https://codeload.github.com/rspack-contrib/rsbuild-plugin-typed-css-modules/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860167,"owners_count":21173342,"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":["rsbuild","rsbuild-plugin","rspack"],"created_at":"2024-08-02T13:00:50.050Z","updated_at":"2025-04-14T10:13:25.117Z","avatar_url":"https://github.com/rspack-contrib.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Rsbuild Plugins"],"readme":"# @rsbuild/plugin-typed-css-modules\n\nAn Rsbuild plugin to generate TypeScript declaration files for CSS Modules.\n\n\u003cp\u003e\n  \u003ca href=\"https://npmjs.com/package/@rsbuild/plugin-typed-css-modules\"\u003e\n   \u003cimg src=\"https://img.shields.io/npm/v/@rsbuild/plugin-typed-css-modules?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"npm version\" /\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square\u0026colorA=564341\u0026colorB=EDED91\" alt=\"license\" /\u003e\n\u003c/p\u003e\n\n## Usage\n\nInstall:\n\n```bash\nnpm add @rsbuild/plugin-typed-css-modules -D\n```\n\nAdd plugin to your `rsbuild.config.ts`:\n\n```ts\n// rsbuild.config.ts\nimport { pluginTypedCSSModules } from \"@rsbuild/plugin-typed-css-modules\";\n\nexport default {\n  plugins: [pluginTypedCSSModules()],\n};\n```\n\n## Example\n\nBy adding the Typed CSS Modules plugin, Rsbuild will generate TypeScript declaration files for all CSS Modules in the project.\n\nFor example, create two files named `src/index.ts` and `src/index.module.css`:\n\n```tsx title=\"src/index.ts\"\nimport styles from \"./index.module.css\";\n\nconsole.log(styles.pageHeader);\n```\n\n```css title=\"src/index.module.css\"\n.page-header {\n  color: black;\n}\n```\n\nAfter building, Rsbuild will generate a `src/index.module.css.d.ts` type declaration file:\n\n```ts title=\"src/index.module.css.d.ts\"\ninterface CssExports {\n  \"page-header\": string;\n  pageHeader: string;\n}\ndeclare const cssExports: CssExports;\nexport default cssExports;\n```\n\nNow when you open the `src/index.ts` file, you can see that the `styles` object already has an accurate type.\n\n## Named Export\n\nIf [output.cssModules.namedExport](/config/output/css-modules#cssmodulesnamedexport) is enabled, the generated type declaration file will only include named exports.\n\nFor example:\n\n```css title=\"index.module.css\"\n.page {\n  color: black;\n}\n.header {\n  color: white;\n}\n```\n\nThe generated types would be:\n\n```ts title=\"src/index.module.css.d.ts\"\nexport const page: string;\nexport const header: string;\n```\n\n## Configure Git\n\nIn the above example, `src/index.module.css.d.ts` is generated by compilation, you can choose to commit them to the Git repository, or you can choose to ignore them in the `.gitignore` file:\n\n```bash\n# Ignore auto generated CSS declarations\n*.module.css.d.ts\n*.module.sass.d.ts\n*.module.scss.d.ts\n*.module.less.d.ts\n*.module.styl.d.ts\n*.module.stylus.d.ts\n```\n\nIn addition, if the generated code causes ESLint to report errors, you can also add the above configuration to the `.eslintignore` file.\n\n## Credits\n\nThe loader was forked from [seek-oss/css-modules-typescript-loader](https://github.com/seek-oss/css-modules-typescript-loader).\n\n## License\n\n[MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frspack-contrib%2Frsbuild-plugin-typed-css-modules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frspack-contrib%2Frsbuild-plugin-typed-css-modules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frspack-contrib%2Frsbuild-plugin-typed-css-modules/lists"}