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['#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
|
||||
nuxt.options.alias.vue2 = resolveModule('vue/dist/vue.runtime.esm.js', { paths: nuxt.options.modulesDir })
|
||||
nuxt.options.build.transpile.push('vue')
|
||||
|
@ -114,6 +114,7 @@ export function setupNitroBridge () {
|
||||
|
||||
// Generate mjs resources
|
||||
nuxt.hook('build:compiled', async ({ name }) => {
|
||||
if (nuxt.options._prepare) { return }
|
||||
if (name === 'server') {
|
||||
const jsServerEntry = resolve(nuxt.options.buildDir, 'dist/server/server.js')
|
||||
await fsp.writeFile(jsServerEntry.replace(/.js$/, '.cjs'), 'module.exports = require("./server.js")', 'utf8')
|
||||
@ -145,7 +146,7 @@ export function setupNitroBridge () {
|
||||
})
|
||||
|
||||
// nuxt prepare
|
||||
nuxt.hook('builder:generateApp', async () => {
|
||||
nuxt.hook('build:done', async () => {
|
||||
nitroDevContext.scannedMiddleware = await scanMiddleware(nitroDevContext._nuxt.serverDir)
|
||||
await writeTypes(nitroDevContext)
|
||||
})
|
||||
@ -155,6 +156,7 @@ export function setupNitroBridge () {
|
||||
nuxt.options.build._minifyServer = false
|
||||
nuxt.options.build.standalone = false
|
||||
nuxt.hook('build:done', async () => {
|
||||
if (nuxt.options._prepare) { return }
|
||||
if (nuxt.options.dev) {
|
||||
await build(nitroDevContext)
|
||||
} 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 { loadKit } from '../utils/kit'
|
||||
import { writeTypes } from '../utils/prepare'
|
||||
@ -18,6 +20,8 @@ export default defineNuxtCommand({
|
||||
const nuxt = await loadNuxt({ rootDir, config: { _prepare: true } })
|
||||
await clearDir(nuxt.options.buildDir)
|
||||
|
||||
await buildNuxt(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[] = []
|
||||
|
||||
await nuxt.callHook('builder:generateApp')
|
||||
await nuxt.callHook('prepare:types', { references, declarations, tsConfig })
|
||||
|
||||
const declaration = [
|
||||
|
@ -20,8 +20,10 @@ export async function build (nuxt: Nuxt) {
|
||||
}
|
||||
|
||||
await nuxt.callHook('build:before', { nuxt }, nuxt.options.build)
|
||||
if (!nuxt.options._prepare) {
|
||||
await bundle(nuxt)
|
||||
await nuxt.callHook('build:done', { nuxt })
|
||||
}
|
||||
|
||||
if (!nuxt.options.dev) {
|
||||
await nuxt.callHook('close', nuxt)
|
||||
|
Loading…
Reference in New Issue
Block a user