Skip to content

🐛 [BUG] - isProductionEnv() not removed at build time #544

@chiefcll

Description

@chiefcll

Description

When running a production build with Vite

export function isProductionEnvironment(): boolean {
  return import.meta.env && import.meta.env.PROD;
}

Is never fully removed from the build because import.meta.env.PROD is true and import.meta.env must be checked at runtime.

Alternatively, if you do:

function isDevEnv(): boolean {
  return !!(import.meta.env && import.meta.env.DEV);
}
export const isDev = isDevEnv() || false;

And check for isDev (not a function) - it will be able to remove all the functions because dev is false and the const becomes false at build time.

Currently all the assertTruthy are left in at runtime as well as isProductionEnvironement() checks. You may need to do isDev && assertTruthy to fully remove them

Reproduction URL

None

Reproduction steps

`vite build`
check output in dist directory

Screenshots

![DESCRIPTION](LINK.png)

Logs

Browsers

Other

Browser version

All

OS

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions