{"id":15495819,"url":"https://github.com/kejunmao/vite-plugin-conditional-compile","last_synced_at":"2025-08-21T08:31:29.576Z","repository":{"id":61271627,"uuid":"548984388","full_name":"KeJunMao/vite-plugin-conditional-compile","owner":"KeJunMao","description":"Conditional compilation syntax based on environment variables for Vite. Vite 下基于环境变量的条件编译","archived":false,"fork":false,"pushed_at":"2024-01-25T10:55:55.000Z","size":283,"stargazers_count":64,"open_issues_count":4,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-24T20:08:25.095Z","etag":null,"topics":["compiler","conditional","vite"],"latest_commit_sha":null,"homepage":"https://github.com/KeJunMao/unplugin-preprocessor-directives","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/KeJunMao.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":"2022-10-10T13:48:30.000Z","updated_at":"2024-10-21T17:07:34.000Z","dependencies_parsed_at":"2024-01-07T18:05:28.912Z","dependency_job_id":"ce6695a7-4597-4712-b252-1df949446ee1","html_url":"https://github.com/KeJunMao/vite-plugin-conditional-compile","commit_stats":{"total_commits":27,"total_committers":1,"mean_commits":27.0,"dds":0.0,"last_synced_commit":"7df29111f2150737cba5cebd359f07385388b0a8"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeJunMao%2Fvite-plugin-conditional-compile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeJunMao%2Fvite-plugin-conditional-compile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeJunMao%2Fvite-plugin-conditional-compile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KeJunMao%2Fvite-plugin-conditional-compile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KeJunMao","download_url":"https://codeload.github.com/KeJunMao/vite-plugin-conditional-compile/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230501172,"owners_count":18236061,"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":["compiler","conditional","vite"],"created_at":"2024-10-02T08:19:46.348Z","updated_at":"2024-12-19T21:10:26.479Z","avatar_url":"https://github.com/KeJunMao.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"300\" src=\"./assets/logo.svg\" alt=\"logo of vite-plugin-conditional-compiler repository\"\u003e\n\u003c/p\u003e\n\n\u003ch2 align='center'\u003evite-plugin-conditional-compiler\u003c/h2\u003e\n\n\u003cp align=\"center\"\u003eConditional compilation syntax based on environment variables\u003c/p\u003e\n\nEnglish | [简体中文](./README.zh-CN.md)\n\n\u003e **Important**\n\u003e From v0.2.0, this plugin is essentially an wrapper of [unplugin-preprocessor-directives](https://github.com/KeJunMao/unplugin-preprocessor-directives).\n\n## Installation\n\n```\npnpm i -D vite-plugin-conditional-compiler\n```\n\n## Usage\n\n```ts\n// vite.config.ts\nimport { defineConfig } from \"vite\";\nimport ConditionalCompile from \"vite-plugin-conditional-compiler\";\n\nexport default defineConfig({\n  plugins: [ConditionalCompile()],\n});\n```\n\n## Syntax\n\nStart with `#v-ifdef`, then append `%ENV%`, end with `#v-endif`, you can also use `#v-elif` and `#v-else`.\n\n- `#v-ifdef`: if defined\n- `%ENV%` Vite environment variables\n\n\u003e **Warning**\n\u003e The `#v-ifndef` is deprecated in the v0.2.0 version\n\n## Configuration\n\n```ts\nexport interface Options {\n  /**\n   * @default [\"**/*\"]\n   */\n  include: FilterPattern;\n  /**\n   * @default []\n   */\n  exclude: FilterPattern;\n}\n```\n\n## Examples\n\n```js\n// Compile in production environment only\n// #v-ifdef PROD\nvalue = 1;\n// #v-endif\n```\n\n```js\n// Condition or, not supported \u0026\u0026\n// Compile in production or development\n// #v-ifdef PROD||DEV\nvalue = 1;\n// #v-endif\n```\n\n```js\n// Allow custom environment variables\n// Compile only when 'VITE_MY_ENV' exists and is not false\n// #v-ifdef VITE_MY_ENV\nvalue = 1;\n// #v-endif\n```\n\n```js\n// Allow specified values\n// Compile only when 'VITE_MY_ENV' exists and is not equal to hi\n// #v-ifdef VITE_MY_ENV!='hi'\nvalue = 1;\n// #v-endif\n```\n\n## Other\n\nWith the better-comments plugin in VsCode, syntax can be highlighted\n\n```json\n{\n  \"tag\": \"#v\",\n  \"color\": \"#fff\",\n  \"strikethrough\": false,\n  \"underline\": false,\n  \"backgroundColor\": \"#0000ff\",\n  \"bold\": true,\n  \"italic\": false\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkejunmao%2Fvite-plugin-conditional-compile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkejunmao%2Fvite-plugin-conditional-compile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkejunmao%2Fvite-plugin-conditional-compile/lists"}