UNPKG

nuxi

Version:
110 lines (109 loc) 3.81 kB
import { t as defineCommand } from "./dist-B03QHgrC.mjs"; import { n as colors } from "./consola.DXBYu-KD-qSGefJ79.mjs"; import "./utils-MaFlCoS1.mjs"; import { a as legacyRootDirArgs, i as extendsArgs, n as dotEnvArgs, o as logLevelArgs, r as envNameArgs, s as profileArgs, t as cwdArgs } from "./_shared-D6pJgr6t.mjs"; import { g as ye, n as logger, u as ge } from "./logger-CtlB9piy.mjs"; import { t as overrideEnv } from "./env-DUdYa0ce.mjs"; import { c as resolve, s as relative } from "./pathe.M-eThtNZ-BfnU2wdd.mjs"; import { a as stopCpuProfile, i as startCpuProfile, n as formatLockError, t as acquireLock } from "./lockfile-Cj3CjE5w.mjs"; import { t as loadKit } from "./kit-Bx45zdA5.mjs"; import { n as showBanner } from "./banner-1xgvoFgm.mjs"; import { t as clearBuildDir } from "./fs-qJl3Qqxr.mjs"; import process from "node:process"; //#region src/commands/build.ts var build_default = defineCommand({ meta: { name: "build", description: "Build Nuxt for production deployment" }, args: { ...cwdArgs, ...logLevelArgs, prerender: { type: "boolean", description: "Build Nuxt and prerender static routes" }, preset: { type: "string", description: "Nitro server preset" }, ...dotEnvArgs, ...envNameArgs, ...extendsArgs, ...profileArgs, ...legacyRootDirArgs }, async run(ctx) { overrideEnv("production"); const cwd = resolve(ctx.args.cwd || ctx.args.rootDir); const profileArg = ctx.args.profile; const perfValue = profileArg === "verbose" ? true : profileArg ? "quiet" : void 0; if (profileArg) await startCpuProfile(); let releaseLock; try { ge(colors.cyan("Building Nuxt for production...")); const kit = await loadKit(cwd); const nuxt = await kit.loadNuxt({ cwd, ready: false, dotenv: { cwd, fileName: ctx.args.dotenv }, envName: ctx.args.envName, overrides: { logLevel: ctx.args.logLevel, _generate: ctx.args.prerender, nitro: { static: ctx.args.prerender, preset: ctx.args.preset || process.env.NITRO_PRESET || process.env.SERVER_PRESET }, ...ctx.args.extends && { extends: ctx.args.extends }, ...ctx.data?.overrides, ...(perfValue || ctx.data?.overrides?.debug) && { debug: { ...ctx.data?.overrides?.debug, ...perfValue && { perf: perfValue } } } } }); showBanner(nuxt); await nuxt.ready(); const lock = acquireLock(nuxt.options.buildDir, { command: "build", cwd }); if (lock.existing) { logger.error(formatLockError(lock.existing)); throw new Error(`Another Nuxt ${lock.existing.command} is already running (PID ${lock.existing.pid}).`); } releaseLock = lock.release; let nitro; try { nitro = kit.useNitro?.(); if (nitro) logger.info(`Nitro preset: ${colors.cyan(nitro.options.preset)}`); } catch {} await clearBuildDir(nuxt.options.buildDir); await kit.writeTypes(nuxt); nuxt.hook("build:error", async (err) => { logger.error(`Nuxt build error: ${err}`); if (profileArg) await stopCpuProfile(cwd, "build"); process.exit(1); }); await kit.buildNuxt(nuxt); if (ctx.args.prerender) { if (!nuxt.options.ssr) { logger.warn(`HTML content not prerendered because ${colors.cyan("ssr: false")} was set.`); logger.info(`You can read more in ${colors.cyan("https://nuxt.com/docs/getting-started/deployment#static-hosting")}.`); } const dir = nitro?.options.output.publicDir; const publicDir = dir ? relative(process.cwd(), dir) : ".output/public"; ye(`✨ You can now deploy ${colors.cyan(publicDir)} to any static hosting!`); } else ye("✨ Build complete!"); } finally { releaseLock?.(); if (profileArg) await stopCpuProfile(cwd, "build"); } } }); //#endregion export { build_default as default };