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 totrue
withnuxt
dev
is forced tofalse
withnuxt build
,nuxt start
andnuxt generate
This property should be used when using Nuxt.js programmatically:
Example:
nuxt.config.js
export default {
dev: (process.env.NODE_ENV !== 'production')
}
server.js
const { Nuxt, Builder } = require('nuxt')
const app = require('express')()
const port = process.env.PORT || 3000
// We instantiate Nuxt.js with the options
const config = require('./nuxt.config.js')
const nuxt = new Nuxt(config)
app.use(nuxt.render)
// Build only in dev mode
if (config.dev) {
new Builder(nuxt).build()
}
// Listen the server
app.listen(port, '0.0.0.0').then(() => {
console.log(`Server is listening on port: ${port}`)
})
Then in your package.json
:
{
"scripts": {
"dev": "node server.js",
"build": "nuxt build",
"start": "cross-env NODE_ENV=production node server.js"
}
}
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.