mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 16:43:55 +00:00
31 lines
750 B
TypeScript
Executable File
31 lines
750 B
TypeScript
Executable File
import { resolve } from 'path'
|
|
import { loadNuxt, build } from '.'
|
|
|
|
async function _main () {
|
|
const args = process.argv.splice(2)
|
|
const cmd = args[0]
|
|
if (!['dev', 'build'].includes(cmd)) {
|
|
// eslint-disable-next-line no-console
|
|
console.error('Usage nuxt dev|build [rootDir]')
|
|
process.exit(1)
|
|
}
|
|
const isDev = cmd === 'dev'
|
|
const rootDir = resolve(process.cwd(), args[1] || '.')
|
|
const nuxt = await loadNuxt({ for: isDev ? 'dev' : 'build', rootDir })
|
|
|
|
if (isDev) {
|
|
// https://github.com/nuxt-contrib/listhen
|
|
await nuxt.server.listen(3000, { name: 'Nuxt' })
|
|
}
|
|
|
|
await build(nuxt)
|
|
}
|
|
|
|
export function main () {
|
|
_main()
|
|
.catch((error) => {
|
|
require('consola').fatal(error)
|
|
require('exit')(2)
|
|
})
|
|
}
|