{"id":17506566,"url":"https://github.com/chf007/vite-plugin-nx-dotenv","last_synced_at":"2026-05-08T15:17:19.513Z","repository":{"id":57678463,"uuid":"486203591","full_name":"chf007/vite-plugin-nx-dotenv","owner":"chf007","description":"vite-plugin-nx-dotenv","archived":false,"fork":false,"pushed_at":"2024-02-28T04:35:03.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-30T07:49:40.490Z","etag":null,"topics":["nx","vite","vite-plugin","vue"],"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/chf007.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-04-27T13:27:39.000Z","updated_at":"2022-09-12T02:29:00.000Z","dependencies_parsed_at":"2024-10-05T12:30:46.727Z","dependency_job_id":"e855947e-2815-454e-85cd-ffd9f47e1c1d","html_url":"https://github.com/chf007/vite-plugin-nx-dotenv","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":0.09999999999999998,"last_synced_commit":"f9985bd47b40b4dd904c92ee40e74c88da6a34e1"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chf007/vite-plugin-nx-dotenv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chf007%2Fvite-plugin-nx-dotenv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chf007%2Fvite-plugin-nx-dotenv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chf007%2Fvite-plugin-nx-dotenv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chf007%2Fvite-plugin-nx-dotenv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chf007","download_url":"https://codeload.github.com/chf007/vite-plugin-nx-dotenv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chf007%2Fvite-plugin-nx-dotenv/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268266399,"owners_count":24222641,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["nx","vite","vite-plugin","vue"],"created_at":"2024-10-20T03:45:26.554Z","updated_at":"2026-05-08T15:17:14.488Z","avatar_url":"https://github.com/chf007.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-plugin-nx-dotenv\n\nSupport Vite's [mode] mode of dotenv usage in Nx, according to the following priorities [[issue](https://github.com/ZachJW34/nx-plus/issues/239)] :\n\n1. /apps/[app]/.env.[mode].local\n2. /apps/[app]/.env.[mode]\n3. /apps/[app]/.env.local\n4. /apps/[app]/.env\n5. /.env.[mode].local\n6. /.env.[mode]\n7. /.env.local\n8. /.env\n\n\u003e There is a little limitation in use. If the environment variable passed in through the command line is defined in .env, it will be overwritten by the one in .env. According to normal logic, the command line should have the highest priority.\n\u003e \n\u003e However, this usage is rare, and it is generally only used during temporary debugging, so it has little impact.\n\n## Getting Started\n\n### Install Plugin\n\n```shell\n# npm\nnpm install vite-plugin-nx-dotenv --save-dev\n\n# yarn\nyarn add vite-plugin-nx-dotenv --dev\n```\n\n### [WorkspaceRoot]/vite.base.config.ts\n\n```typescript\nimport { join } from 'path';\nimport { ConfigEnv, UserConfigExport, Plugin } from 'vite';\nimport { workspaceRoot } from '@nrwl/tao/src/utils/app-root';\n\nimport VueSetupExtend from 'vite-plugin-vue-setup-extend';\nimport vue from '@vitejs/plugin-vue';\nimport vueJsx from '@vitejs/plugin-vue-jsx';\nimport { createHtmlPlugin } from 'vite-plugin-html';\n\nimport { nxDotEnvSupport } from 'vite-plugin-nx-dotenv';\n\n// https://vitejs.dev/config/\nexport const viteBaseConfig = async ({ command, mode }: ConfigEnv, nxDotEnv: any) =\u003e {\n\n  // 配置项\n  const config: UserConfigExport = {\n    plugins: [\n      nxDotEnvSupport({\n        globalEnvDir: workspaceRoot,\n      }),\n      vue(),\n      vueJsx(),\n      VueSetupExtend(),\n      createHtmlPlugin({\n        inject: {\n          data: {\n            CURRENT_ENV: mode,\n            MOCK_ID: nxDotEnv.VITE_MOCK_ID,\n          },\n        },\n      }),\n    ],\n  };\n\n  config.base = './';\n\n  return config;\n};\n\n```\n\n### [WorkspaceRoot]/apps/xxx/vite.config.ts\n\n```typescript\nimport { defineConfig } from 'vite';\nimport { workspaceRoot } from '@nrwl/tao/src/utils/app-root';\nimport { viteBaseConfig } from '../../vite.base.config';\nimport { loadNxDotEnv } from 'vite-plugin-nx-dotenv';\nimport _ from 'lodash';\n\n// https://vitejs.dev/config/\nexport default defineConfig(async ({ command, mode }) =\u003e {\n\n    const nxDotEnv = loadNxDotEnv(mode, __dirname, workspaceRoot);\n\n    return _.merge(\n        {\n            root: __dirname,\n            build: {\n                outDir: '../../dist/apps/xxx',\n                emptyOutDir: true,\n            },\n            server: {\n                port: 4000,\n                open: `/demo?id=${nxDotEnv.VITE_MOCK_ID}`,\n            },\n        },\n        await viteBaseConfig({ command, mode }, nxDotEnv),\n    );\n});\n\n\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchf007%2Fvite-plugin-nx-dotenv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchf007%2Fvite-plugin-nx-dotenv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchf007%2Fvite-plugin-nx-dotenv/lists"}