nitrojs / nitrojs/nitro

Add `import.meta.envName` for build EnvName

Open
#3,041 9 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion enhancement v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Describe the feature
Describe the feature

The current implementation of envName in Nuxt allows for custom environment names (e.g., staging) to be defined at build time, as per the documentation https://nuxt.com/docs/api/commands/build#options & https://nuxt.com/docs/getting-started/configuration#environment-overrides. However, there is no straightforward way to access this custom envName at runtime.

Proposal:
Introduce import.meta.envName to reflect the custom envName defined during the build process. By default, it would to return production, development, or test, but when a custom envName is provided, it would return the defined value (e.g., staging).

Use Cases:

  1. Styling and Customization:

    if (import.meta.envName === 'staging') {
        setLogoColor('blue');
    }
    
  2. Third-Party Module Configuration:

    import * as Sentry from '@sentry/browser';
    
    Sentry.init({
        dsn: 'https://example@sentry.io/12345',
        environment: import.meta.envName, // Pass environment, 'staging' for example
    });
    
Additional information
  • Would you be willing to help implement this feature?

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 Nuxt build-option and environment-overrides documentation linked in the issue, then trace Nitro's existing build-time envName handling and runtime entry points. Done means import.meta.envName exposes production, development, and test by default, while returning a custom value such as staging when one is configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
nuxt, typescript
Domain
backend, build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.