mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 01:15:58 +00:00
fix(nuxi,nuxt3,bridge): generate all templates with nuxi prepare
(#2409)
This commit is contained in:
parent
7553849371
commit
03cc1913a3
@ -10,6 +10,13 @@ export function setupAppBridge (_options: any) {
|
|||||||
nuxt.options.alias['#app'] = resolve(distDir, 'runtime/index.mjs')
|
nuxt.options.alias['#app'] = resolve(distDir, 'runtime/index.mjs')
|
||||||
nuxt.options.alias['#build'] = nuxt.options.buildDir
|
nuxt.options.alias['#build'] = nuxt.options.buildDir
|
||||||
|
|
||||||
|
// Mock `bundleBuilder.build` to support `nuxi prepare`
|
||||||
|
if (nuxt.options._prepare) {
|
||||||
|
nuxt.hook('builder:prepared', (builder) => {
|
||||||
|
builder.bundleBuilder.build = () => Promise.resolve(builder.bundleBuilder)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Resolve vue2 builds
|
// Resolve vue2 builds
|
||||||
nuxt.options.alias.vue2 = resolveModule('vue/dist/vue.runtime.esm.js', { paths: nuxt.options.modulesDir })
|
nuxt.options.alias.vue2 = resolveModule('vue/dist/vue.runtime.esm.js', { paths: nuxt.options.modulesDir })
|
||||||
nuxt.options.build.transpile.push('vue')
|
nuxt.options.build.transpile.push('vue')
|
||||||
|
@ -114,6 +114,7 @@ export function setupNitroBridge () {
|
|||||||
|
|
||||||
// Generate mjs resources
|
// Generate mjs resources
|
||||||
nuxt.hook('build:compiled', async ({ name }) => {
|
nuxt.hook('build:compiled', async ({ name }) => {
|
||||||
|
if (nuxt.options._prepare) { return }
|
||||||
if (name === 'server') {
|
if (name === 'server') {
|
||||||
const jsServerEntry = resolve(nuxt.options.buildDir, 'dist/server/server.js')
|
const jsServerEntry = resolve(nuxt.options.buildDir, 'dist/server/server.js')
|
||||||
await fsp.writeFile(jsServerEntry.replace(/.js$/, '.cjs'), 'module.exports = require("./server.js")', 'utf8')
|
await fsp.writeFile(jsServerEntry.replace(/.js$/, '.cjs'), 'module.exports = require("./server.js")', 'utf8')
|
||||||
@ -145,7 +146,7 @@ export function setupNitroBridge () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// nuxt prepare
|
// nuxt prepare
|
||||||
nuxt.hook('builder:generateApp', async () => {
|
nuxt.hook('build:done', async () => {
|
||||||
nitroDevContext.scannedMiddleware = await scanMiddleware(nitroDevContext._nuxt.serverDir)
|
nitroDevContext.scannedMiddleware = await scanMiddleware(nitroDevContext._nuxt.serverDir)
|
||||||
await writeTypes(nitroDevContext)
|
await writeTypes(nitroDevContext)
|
||||||
})
|
})
|
||||||
@ -155,6 +156,7 @@ export function setupNitroBridge () {
|
|||||||
nuxt.options.build._minifyServer = false
|
nuxt.options.build._minifyServer = false
|
||||||
nuxt.options.build.standalone = false
|
nuxt.options.build.standalone = false
|
||||||
nuxt.hook('build:done', async () => {
|
nuxt.hook('build:done', async () => {
|
||||||
|
if (nuxt.options._prepare) { return }
|
||||||
if (nuxt.options.dev) {
|
if (nuxt.options.dev) {
|
||||||
await build(nitroDevContext)
|
await build(nitroDevContext)
|
||||||
} else if (!nitroContext._nuxt.isStatic) {
|
} else if (!nitroContext._nuxt.isStatic) {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import { resolve } from 'pathe'
|
import { buildNuxt } from '@nuxt/kit'
|
||||||
|
import { relative, resolve } from 'pathe'
|
||||||
|
import consola from 'consola'
|
||||||
import { clearDir } from '../utils/fs'
|
import { clearDir } from '../utils/fs'
|
||||||
import { loadKit } from '../utils/kit'
|
import { loadKit } from '../utils/kit'
|
||||||
import { writeTypes } from '../utils/prepare'
|
import { writeTypes } from '../utils/prepare'
|
||||||
@ -18,6 +20,8 @@ export default defineNuxtCommand({
|
|||||||
const nuxt = await loadNuxt({ rootDir, config: { _prepare: true } })
|
const nuxt = await loadNuxt({ rootDir, config: { _prepare: true } })
|
||||||
await clearDir(nuxt.options.buildDir)
|
await clearDir(nuxt.options.buildDir)
|
||||||
|
|
||||||
|
await buildNuxt(nuxt)
|
||||||
await writeTypes(nuxt)
|
await writeTypes(nuxt)
|
||||||
|
consola.success('Types generated in', relative(process.cwd(), nuxt.options.buildDir))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -67,7 +67,6 @@ export const writeTypes = async (nuxt: Nuxt) => {
|
|||||||
|
|
||||||
const declarations: string[] = []
|
const declarations: string[] = []
|
||||||
|
|
||||||
await nuxt.callHook('builder:generateApp')
|
|
||||||
await nuxt.callHook('prepare:types', { references, declarations, tsConfig })
|
await nuxt.callHook('prepare:types', { references, declarations, tsConfig })
|
||||||
|
|
||||||
const declaration = [
|
const declaration = [
|
||||||
|
@ -20,8 +20,10 @@ export async function build (nuxt: Nuxt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await nuxt.callHook('build:before', { nuxt }, nuxt.options.build)
|
await nuxt.callHook('build:before', { nuxt }, nuxt.options.build)
|
||||||
await bundle(nuxt)
|
if (!nuxt.options._prepare) {
|
||||||
await nuxt.callHook('build:done', { nuxt })
|
await bundle(nuxt)
|
||||||
|
await nuxt.callHook('build:done', { nuxt })
|
||||||
|
}
|
||||||
|
|
||||||
if (!nuxt.options.dev) {
|
if (!nuxt.options.dev) {
|
||||||
await nuxt.callHook('close', nuxt)
|
await nuxt.callHook('close', nuxt)
|
||||||
|
Loading…
Reference in New Issue
Block a user