Skip to content

Instantly share code, notes, and snippets.

@cannap
Created September 13, 2017 12:45
Show Gist options
  • Select an option

  • Save cannap/f86b91f5bb1d3680234c46b6d6e2720a to your computer and use it in GitHub Desktop.

Select an option

Save cannap/f86b91f5bb1d3680234c46b6d6e2720a to your computer and use it in GitHub Desktop.
const { hooks } = require('@adonisjs/ignitor')
hooks.after.httpServer(() => {
use('App/Controllers/Http/NuxtController')
})
const Config = use('Config')
const { Command } = require('@adonisjs/ace')
const { Nuxt, Builder } = require('nuxt')
class NuxtBuild extends Command {
static get signature () {
return 'nuxt:build'
}
static get description () {
return 'Build nuxt app for production'
}
async handle (args, options) {
let config = Config.get('nuxt')
config.dev = false
this.nuxt = new Nuxt(config)
this.info('Building nuxt app for production')
try {
await new Builder(this.nuxt).build()
this.info('Production build completed')
} catch (error) {
console.log('NuxtBuild Error', error)
}
}
}
module.exports = NuxtBuild
const { Nuxt, Builder } = require('nuxt')
const Env = use('Env')
const Config = use('Config')
class NuxtController {
constructor () {
let config = Config.get('nuxt')
config.dev = Env.get('NODE_ENV') === 'development'
this.nuxt = new Nuxt(config)
// Start build process (only in development)
if (config.dev) {
new Builder(this.nuxt).build().catch(error => {
console.error(error)
process.exit(1)
})
}
}
render ({ request, response }) {
response.implicitEnd = false
this.nuxt.render(request.request, response.response)
}
}
module.exports = new NuxtController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment