winglang / winglang/wing

@winglibs/vite use native environment variables vs global wing object

Open
#7,101 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

✨ enhancement 📚 libraries needs-discussion
Dominant language
TypeScript
Stars
5.4k
Forks
215
Avg merge
2h 9m
Merged PRs (30d)
27

Description

Use Case

I'm building an application and trying to share the API URL.

bring cloud;
bring vite;


let freinds: Array<Json> = [
  {name: "John", email: "test@test.com"},
  {name: "John", email: "random@test.com"},
];

let api = new cloud.Api();

api.get("/friends", inflight () => {
  return cloud.ApiResponse {
    body: Json.stringify(freinds)
  };
});

// Create the website

let website = new vite.Vite(
  root: "../ui",
  publicEnv: {
    API_URL: api.url,
  },
);

In the vite code I have to access this using window.wing.env but vite has it's own eco system and ways to share public ENV variables, it would be nice to support this. So Front end developers don't have to care about a wing global object, they continue to write applications as they were.

Proposed Solution

Let me just use Vite import syntax to get what I want https://vitejs.dev/guide/env-and-mode

For example import.meta.env gives me all the environment variables, I would expected to see it on there import.meta.env.API_URL in this example.

Implementation Notes

No response

Component

No response

Community Notes
  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.
  • If this issue is labeled needs-discussion, it means the spec has not been finalized yet. Please reach out on the #dev channel in the Wing Discord.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the winglibs/vite Vite component and compare its current publicEnv/window.wing.env behavior with the linked Vite env-and-mode documentation. Determine how API_URL should appear through import.meta.env, then verify that a Vite frontend can consume it without relying on the Wing global object.

Written by the indexing model from the issue text.

Assessment

Tech stack
vite
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.