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-04-09 15:52:45 +00:00
|
|
|
|
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-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',
|
2021-08-10 17:37:03 +00:00
|
|
|
usage: 'npx nuxi build [rootDir]',
|
2021-07-26 14:04:35 +00:00
|
|
|
description: 'Build nuxt for production deployment'
|
|
|
|
},
|
|
|
|
async invoke (args) {
|
|
|
|
process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
|
|
|
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
|
|
|
|
2021-07-26 14:04:35 +00:00
|
|
|
const nuxt = await loadNuxt({ rootDir })
|
2021-07-15 11:24:26 +00:00
|
|
|
|
2021-10-07 13:53:31 +00:00
|
|
|
await writeTypes(nuxt)
|
|
|
|
|
2021-07-26 14:04:35 +00:00
|
|
|
nuxt.hook('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)
|
|
|
|
}
|
|
|
|
})
|