Skip to content

How do I define an constant variable with EsBuild? #762

Answered by userquin
Pentadome asked this question in Q&A
Discussion options

You must be logged in to vote

You should:

  • add /// <reference types="vite/client" /> to your service worker
  • add .env file and prefix public entries with VITE_ and use import.meta.env.VITE_XXX: there is no way to access any process.env variable from the service worker (Nuxt will not expose any vite.define nor runtimeConfig.public in import.meta.env (also checked vite.define.envPrefix = ['VITE_', 'NUXT_'])

https://stackblitz.com/edit/github-4afvcv-xu75vp?file=nuxt.config.ts,pwa%2FcustomServiceWorker.ts,.env

Replies: 1 comment 12 replies

Comment options

You must be logged in to vote
12 replies
@userquin
Comment options

@userquin
Comment options

@Pentadome
Comment options

@userquin
Comment options

Answer selected by Pentadome
@userquin
Comment options

@userquin
Comment options

@Pentadome
Comment options

@userquin
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants