Created
September 13, 2017 12:45
-
-
Save cannap/f86b91f5bb1d3680234c46b6d6e2720a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { hooks } = require('@adonisjs/ignitor') | |
| hooks.after.httpServer(() => { | |
| use('App/Controllers/Http/NuxtController') | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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