{"id":13485025,"url":"https://github.com/vbenjs/vite-plugin-style-import","last_synced_at":"2025-08-24T02:30:54.688Z","repository":{"id":36953626,"uuid":"330624606","full_name":"vbenjs/vite-plugin-style-import","owner":"vbenjs","description":"A plug-in that imports component library styles on demand.it is fast","archived":false,"fork":false,"pushed_at":"2023-04-17T09:52:29.000Z","size":3287,"stargazers_count":439,"open_issues_count":36,"forks_count":57,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-05-21T01:11:07.004Z","etag":null,"topics":[],"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/vbenjs.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-18T10:02:23.000Z","updated_at":"2024-06-01T12:11:14.926Z","dependencies_parsed_at":"2024-06-01T12:11:05.707Z","dependency_job_id":"cd1025e6-72ca-4840-a573-50e60f6f0740","html_url":"https://github.com/vbenjs/vite-plugin-style-import","commit_stats":{"total_commits":78,"total_committers":12,"mean_commits":6.5,"dds":"0.41025641025641024","last_synced_commit":"460234fa9accd820a8fd927325f998111e5c44b2"},"previous_names":["anncwb/vite-plugin-style-import"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-style-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-style-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-style-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-style-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vbenjs","download_url":"https://codeload.github.com/vbenjs/vite-plugin-style-import/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230762133,"owners_count":18276619,"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":[],"created_at":"2024-07-31T17:01:43.028Z","updated_at":"2024-12-21T20:07:39.530Z","avatar_url":"https://github.com/vbenjs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# vite-plugin-style-import\n\n**English** | [中文](./README.zh_CN.md)\n\n[![npm][npm-img]][npm-url] [![node][node-img]][node-url]\n\nA plug-in that imports component library styles on demand\n\n## Why only import styles\n\nBecause vite itself has imported the component library on demand, only the style is not on demand, so just import the style on demand.\n\n## Install (yarn or npm)\n\n**node version:** \u003e=12.0.0\n\n**vite version:** \u003e=2.0.0\n\n```\nyarn add vite-plugin-style-import -D\n```\n\nor\n\n```\nnpm i vite-plugin-style-import -D\n```\n\n## Effect\n\n```ts\n\nimport { Button } from 'ant-design-vue';\n\n        ↓ ↓ ↓ ↓ ↓ ↓\n\nimport { Button } from 'ant-design-vue';\nimport 'ant-design-vue/es/button/style/index.js';\n\n```\n\n```ts\n\nimport { ElButton } from 'element-plus';\n\n        ↓ ↓ ↓ ↓ ↓ ↓\n\n// dev\nimport { Button } from 'element-plus';\nimport 'element-plus/lib/theme-chalk/el-button.css`;\n\n// prod\nimport Button from 'element-plus/lib/el-button';\nimport 'element-plus/lib/theme-chalk/el-button.css';\n\n```\n\n## Usage\n\n- Config plugin in vite.config.ts\n\n```ts\nimport { UserConfigExport } from 'vite'\nimport {\n  createStyleImportPlugin,\n  AndDesignVueResolve,\n  VantResolve,\n  ElementPlusResolve,\n  NutuiResolve,\n  AntdResolve,\n} from 'vite-plugin-style-import'\n\nexport default (): UserConfigExport =\u003e {\n  return {\n    // 1. If you are using the ant-design series, you need to configure this\n    // 2. Make sure less is installed in the dependency `yarn add less -D`\n    css: {\n      preprocessorOptions: {\n        less: {\n          javascriptEnabled: true,\n        },\n      },\n    },\n    plugins: [\n      createStyleImportPlugin({\n        resolves: [\n          AndDesignVueResolve(),\n          VantResolve(),\n          ElementPlusResolve(),\n          NutuiResolve(),\n          AntdResolve(),\n        ],\n        libs: [\n          // If you don’t have the resolve you need, you can write it directly in the lib, or you can provide us with PR\n          {\n            libraryName: 'ant-design-vue',\n            esModule: true,\n            resolveStyle: (name) =\u003e {\n              return `ant-design-vue/es/${name}/style/index`\n            },\n          },\n        ],\n      }),\n    ],\n  }\n}\n```\n\n### Options\n\n| param    | type                                                  | default                                          | description                                               |\n| -------- | ----------------------------------------------------- | ------------------------------------------------ | --------------------------------------------------------- |\n| include  | `string、RegExp、(string、RegExp)[]、null、undefined` | `['**/*.js', '**/*.ts', '**/*.tsx', '**/*.jsx']` | Code directory and file format to be converted            |\n| exclude  | `string、RegExp、(string、RegExp)[]、null、undefined` | `'node_modules/**'`                              | Excluded files/folders                                    |\n| libs     | `Lib[]`                                               |                                                  | List of libraries to be imported                          |\n| resolves | `Lib[]`                                               |                                                  | List of libraries to be imported (built-in by the plugin) |\n\n**Lib**\n\n```ts\n{\n  // Import names that meet this rule will take effect. The default is null, which can be applied to resolveComponent and resolveStyle at the same time\n  importTest?: Regexp;\n\n  // Need to imported  library name\n  libraryName: string;\n\n  // Custom style file conversion\n  resolveStyle: (name: string) =\u003e string;\n\n  // Name conversion for library export\n  // default: paramCase\n  libraryNameChangeCase?: LibraryNameChangeCase;\n\n  // If the style file is not .css suffix. Need to turn on this option\n  // default: false\n  esModule?: boolean;\n\n  /**\n   * There may be some component libraries that are not very standardized.\n   * You can turn on this to ignore to determine whether the file exists. Prevent errors when importing non-existent css files.\n   * Performance may be slightly reduced after it is turned on, but the impact is not significant\n   * default: false\n   */\n  ensureStyleFile?: boolean;\n\n\n}\n\n// LibraryNameChangeCase\n\nexport type LibraryNameChangeCase = ChangeCaseType | ((name: string) =\u003e string);\n\nexport type ChangeCaseType =\n  | 'camelCase'\n  | 'capitalCase'\n  | 'constantCase'\n  | 'dotCase'\n  | 'headerCase'\n  | 'noCase'\n  | 'paramCase'\n  | 'pascalCase'\n  | 'pathCase'\n  | 'sentenceCase'\n  | 'snakeCase';\n\n\n```\n\n## Example\n\n**Run Example**\n\n```bash\npnpm install\ncd packages/playground/basic\npnpm run dev\npnpm run build\n```\n\n## Sample project\n\n[Vben Admin](https://github.com/anncwb/vue-vben-admin)\n\n## License\n\nMIT\n\n[npm-img]: https://img.shields.io/npm/v/vite-plugin-style-import.svg\n[npm-url]: https://npmjs.com/package/vite-plugin-style-import\n[node-img]: https://img.shields.io/node/v/vite-plugin-style-import.svg\n[node-url]: https://nodejs.org/en/about/releases/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvbenjs%2Fvite-plugin-style-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvbenjs%2Fvite-plugin-style-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvbenjs%2Fvite-plugin-style-import/lists"}