2021-07-12 10:54:24 +00:00
|
|
|
import { resolve } from 'upath'
|
2021-04-15 19:17:44 +00:00
|
|
|
import { requireModule } from '../utils/cjs'
|
2021-07-15 11:24:26 +00:00
|
|
|
import { error } from '../utils/log'
|
2021-04-09 15:52:45 +00:00
|
|
|
|
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',
|
|
|
|
usage: 'nu build [rootDir]',
|
|
|
|
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-07-26 14:04:35 +00:00
|
|
|
const { loadNuxt, buildNuxt } = requireModule('@nuxt/kit', rootDir) as typeof import('@nuxt/kit')
|
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-07-26 14:04:35 +00:00
|
|
|
nuxt.hook('error', (err) => {
|
|
|
|
error('Nuxt Build Error:', err)
|
|
|
|
process.exit(1)
|
|
|
|
})
|
2021-04-09 15:52:45 +00:00
|
|
|
|
2021-07-26 14:04:35 +00:00
|
|
|
await buildNuxt(nuxt)
|
|
|
|
}
|
|
|
|
})
|