Skip to content

Commit

Permalink
fix: support classic nuxt generation behaviour with --classic CLI a…
Browse files Browse the repository at this point in the history
…rgument
  • Loading branch information
danielroe committed Jul 7, 2022
1 parent 7d0e840 commit e3d8ca1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { promises as fsp, existsSync } from 'fs'
import { pathToFileURL } from 'url'
import fetch from 'node-fetch'
import fsExtra from 'fs-extra'
import { addPluginTemplate, resolvePath, useNuxt } from '@nuxt/kit'
import { addPluginTemplate, importModule, resolvePath, useNuxt } from '@nuxt/kit'
import { joinURL, stringifyQuery, withBase, withoutTrailingSlash } from 'ufo'
import { resolve, join, dirname, normalize } from 'pathe'
import { createNitro, createDevServer, build, writeTypes, prepare, copyPublicAssets, prerender } from 'nitropack'
Expand Down Expand Up @@ -288,6 +288,16 @@ export async function setupNitroBridge () {
return
}

// Invokve classic generation behaviour with --classic CLI argument

const useClassicGeneration = process.argv.includes('--classic')
if (useClassicGeneration && nuxt.options._generate) {
const { Generator } = await importModule('@nuxt/generator')
const generator = new Generator(nuxt)
await generator.generate({ build: false })
return
}

await prerender(nitro)
// Skip Nitro build if we are using `nuxi generate`
if (!nuxt.options._generate) {
Expand Down Expand Up @@ -320,7 +330,7 @@ export async function setupNitroBridge () {
}
})
nuxt.hook('generate:before', async () => {
await nuxt.server.close()
await nuxt.server?.close()
})
nuxt.hook('generate:extendRoutes', async () => {
nuxt.server = await createNuxt2Prerenderer(nitro)
Expand Down

0 comments on commit e3d8ca1

Please sign in to comment.