#How to completely remove dev function from prod?

1 messages · Page 1 of 1 (latest)

bleak tundra
#

I'm trying the following patter:

export function devSleep(ms: number): Promise<void> {
  if (!import.meta.env.DEV) return Promise.resolve()
  return new Promise((resolve) => setTimeout(resolve, ms))
}

It works, but in prod it gets compiled into

  function devSleep(ms) {
    return Promise.resolve();
  }

...

  async function handleIncoming(msg) {
    await devSleep();
    ...
  }

Is there a way in Vite to make it totally disappear from prod code?

languid blaze
#

I think if you don't use the function in Prod code, the function definition should be tree-shaken away

Or do want to remove both the function definition and function usage ?