API: The dev Property

  • Type: Boolean
  • Default: true

Define the development or production mode of Nuxt.js.

This property is overwritten by nuxt commands:

  • dev is forced to true with nuxt
  • dev is forced to false with nuxt build, nuxt start and nuxt generate

This property should be used when using Nuxt.js programmatically:

Example:

nuxt.config.js

  1. export default {
  2. dev: (process.env.NODE_ENV !== 'production')
  3. }

server.js

  1. const { Nuxt, Builder } = require('nuxt')
  2. const app = require('express')()
  3. const port = process.env.PORT || 3000
  4. // We instantiate Nuxt.js with the options
  5. const config = require('./nuxt.config.js')
  6. const nuxt = new Nuxt(config)
  7. app.use(nuxt.render)
  8. // Build only in dev mode
  9. if (config.dev) {
  10. new Builder(nuxt).build()
  11. }
  12. // Listen the server
  13. app.listen(port, '0.0.0.0').then(() => {
  14. console.log(`Server is listening on port: ${port}`)
  15. })

Then in your package.json:

  1. {
  2. "scripts": {
  3. "dev": "node server.js",
  4. "build": "nuxt build",
  5. "start": "cross-env NODE_ENV=production node server.js"
  6. }
  7. }

Note: You'll need to run npm install —save-dev cross-env for the above example to work. If you're not developing on Windows you can leave cross-env out of your start script and set NODE_ENV directly.