Home

Issue: 2855

How to get NODE_ENV=test/dev in statically generated site?

[issue link]

I build and deploy my site to a test server (AWS S3), then hit it with Selenium tests before deploying to the prod server. I call a weather API that only allows me a certain number of calls on the free tier. I would like for NODE_ENV=test nuxt generate to point at test data instead of the actual API. I’ve set the dev: property in nuxt.config.js but it didn’t work. Heres an example of what I’m talking about:

   if (process.env.NODE_ENV === 'production') {
       // Call the real API 
    } else { // Test data
      this.temperature = '70.01'
      this.description = "sunny"
      this.iconId = weatherIcons[Math.floor(Math.random() * weatherIcons.length)].ow
      this.imgLoaded = true
    }
This question is available on Nuxt.js community (#c2479)