2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2021-10-07 10:15:15 +00:00
|
|
|
import consola from 'consola'
|
2021-10-07 13:53:31 +00:00
|
|
|
import { writeTypes } from '../utils/prepare'
|
2021-10-13 10:44:54 +00:00
|
|
|
import { loadKit } from '../utils/kit'
|
2021-10-18 14:22:02 +00:00
|
|
|
import { clearDir } from '../utils/fs'
|
2022-06-12 21:26:36 +00:00
|
|
|
import { overrideEnv } from '../utils/env'
|
2021-07-26 14:04:35 +00:00
|
|
|
import { defineNuxtCommand } from './index'
|
2021-04-15 19:17:44 +00:00
|
|
|
|
2021-07-26 14:04:35 +00:00
|
|
|
export default defineNuxtCommand({
|
|
|
|
meta: {
|
|
|
|
name: 'build',
|
2022-04-07 11:28:04 +00:00
|
|
|
usage: 'npx nuxi build [--prerender] [rootDir]',
|
2021-07-26 14:04:35 +00:00
|
|
|
description: 'Build nuxt for production deployment'
|
|
|
|
},
|
|
|
|
async invoke (args) {
|
2022-06-12 21:26:36 +00:00
|
|
|
overrideEnv('production')
|
|
|
|
|
2021-07-26 14:04:35 +00:00
|
|
|
const rootDir = resolve(args._[0] || '.')
|
2021-04-09 15:52:45 +00:00
|
|
|
|
2021-10-13 10:44:54 +00:00
|
|
|
const { loadNuxt, buildNuxt } = await loadKit(rootDir)
|
2021-07-15 11:24:26 +00:00
|
|
|
|
2022-04-07 11:28:04 +00:00
|
|
|
const nuxt = await loadNuxt({
|
|
|
|
rootDir,
|
|
|
|
overrides: {
|
|
|
|
_generate: args.prerender
|
|
|
|
}
|
|
|
|
})
|
2021-07-15 11:24:26 +00:00
|
|
|
|
2021-10-18 14:22:02 +00:00
|
|
|
await clearDir(nuxt.options.buildDir)
|
|
|
|
|
2021-10-07 13:53:31 +00:00
|
|
|
await writeTypes(nuxt)
|
|
|
|
|
2021-10-20 18:50:01 +00:00
|
|
|
nuxt.hook('build:error', (err) => {
|
2021-10-07 10:15:15 +00:00
|
|
|
consola.error('Nuxt Build Error:', err)
|
2021-07-26 14:04:35 +00:00
|
|
|
process.exit(1)
|
|
|
|
})
|
2021-04-09 15:52:45 +00:00
|
|
|
|
2021-07-26 14:04:35 +00:00
|
|
|
await buildNuxt(nuxt)
|
|
|
|
}
|
|
|
|
})
|