Skip to content

feat: Integrate dynamic API key injection#1519

Open
willum070 wants to merge 10 commits into
mainfrom
update-vite-config-apikeys
Open

feat: Integrate dynamic API key injection#1519
willum070 wants to merge 10 commits into
mainfrom
update-vite-config-apikeys

Conversation

@willum070

@willum070 willum070 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

This PR updates several processes to dynamically inject the production API key, as well as a newly added test API key for local development.

This PR does the following things:

1. vite.config.js (Moved to Monorepo Root)

  • Dynamic API Key Injection: Added a custom Vite HTML Transform Plugin (using enforce: 'pre') that intercepts all HTML, TS, and JS files during both local development (serve) and CI compilation (build). It hunts down the placeholder string "GOOGLE_MAPS_API_KEY" and securely swaps it out with the active environment variable in memory.
  • Dotenv Integration: Configured dotenv to automatically load local development keys from the .env file into process.env when developers run the app locally.
  • Fixes React Path Resolution: Removed the global root override, allowing root to default to process.cwd(). This ensures Vite builds from the context of the active sample directory, fixing module resolution errors where React apps (react-ui-kit-*) were failing to find /src/app.tsx.
  • Fixes Vite 5/Rolldown Crash: Resolved an [INVALID_OPTION] error by updating rollupOptions.input to use a simple string ('index') as the dictionary key rather than an absolute file path.

2. .github/workflows/release.yml

  • Exposes Production Secret: Added GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }} to the environment block of the npm run build-all step. This securely pipes the repository's production API key into the CI runner so the new Vite plugin can inject it into the final dist/ HTML artifacts.

3. .gitignore

  • Config Tracking: Added an explicit exclusion rule (!samples/*/vite.config.js) to prevent the new local config stub files from being accidentally ignored by the legacy samples/*/*.js rule (which was designed to ignore TypeScript compiler outputs).

4. dist.sh

-Removes dist.sh: Removes this file since Vite now copies those files natively.

5. .github/workflows/tests.yml:

-Updates .github/workflows/tests.yml to inject a dedicated development API key (JS_MAPS_DEV) into the global environment variables specifically for the test runner. This was necessary since production keys will no longer allow local port restrictions.

6. All samples:

-Updates all sample projects to replace the production API key with a placeholder (GOOGLE_MAPS_API_KEY).

This architecture completely unifies how API keys are handled across all 80+ samples, eliminating hardcoded dummy strings in production while keeping the developer experience totally seamless!

@willum070 willum070 requested a review from a team as a code owner June 23, 2026 18:00
@willum070 willum070 force-pushed the update-vite-config-apikeys branch 3 times, most recently from 5cab3a5 to 6bb2ce3 Compare June 23, 2026 19:01
@willum070 willum070 force-pushed the update-vite-config-apikeys branch from 6bb2ce3 to 661cc25 Compare June 23, 2026 19:05
@willum070 willum070 requested a review from chrisjshull June 23, 2026 20:31
@willum070 willum070 changed the title Update vite config apikeys Integrate dynamic API key injection Jun 23, 2026
@willum070 willum070 changed the title Integrate dynamic API key injection feat: Integrate dynamic API key injection Jun 23, 2026
@willum070 willum070 force-pushed the update-vite-config-apikeys branch from 07d1272 to a037831 Compare June 23, 2026 21:28
@willum070 willum070 force-pushed the update-vite-config-apikeys branch from 2e0f906 to f988110 Compare June 24, 2026 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant