Skip to content

firebase deploy not running vite build in prod mode #5564

Closed

Description

@tanjunior

[REQUIRED] Environment info

firebase-tools: 11.24.0

Platform: Windows

[REQUIRED] Test case

Create a new vite react project
console.log(import.meta.env.DEV) in app.js
npm run dev
console log return true
npm run build
npm run serve
console log return false
firebase experiments:enable webframeworks
firebase init hosting
firebase deploy
firebase serve
console log return true

[REQUIRED] Steps to reproduce

Create a new vite react project
console.log(import.meta.env.DEV) in app.js
npm run dev
console log return true
npm run build
npm run serve
console log return false
firebase experiments:enable webframeworks
firebase init hosting
firebase deploy
firebase serve
console log return true

[REQUIRED] Expected behavior

console log should return false in a firebase build as it runs npm run build(vite build) and vite build builds in production mode by default

[REQUIRED] Actual behavior

console log return true in a firebase build

Activity

  1. tanjunior commented on Feb 28, 2023

    @tanjunior
    Author

    found a work around by following https://vitejs.dev/guide/static-deploy.html#google-firebase

    change firebase.json hosting from

    "hosting": {
        "source": ".",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "frameworksBackend": {
          "region": "asia-east1"
        }
      }
    

    to

      "hosting": {
        "public": "dist",
        "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ],
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "predeploy": [
          "npm run build"
        ]
      },
    
  2. jamesdaniels commented on Apr 12, 2023

    @jamesdaniels
    Contributor

    We are forcing the Vite build to production, we will override NODE_ENV in a future release but this should be sufficient.

  3. joelharkes commented on Jun 10, 2023

    @joelharkes

    @tanjunior there is no way to run HMR vite in the emulator hosting?

  4. AlxVallecillo commented on Sep 16, 2023

    @AlxVallecillo

    Thank you @tanjunior that worked just fine

  5. mrchantey commented on Jun 23, 2024

    @mrchantey

    I'm still getting dev environment variables when deploying a simple astro project with firebase deploy in firebase-tools 13.11.2:

    import.meta.env.DEV === true
    import.meta.env.PROD === true
    import.meta.env.MODE === 'production'
    
    process.env.NODE_ENV === 'development'
    

    Interestingly the only env that seems to be correct is import.meta.env.MODE.

    The static deploy firebase.json solution won't work for SSR apps using frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions