From 3d1695100a17502dcb49d074ed15627604cd03f0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 10 May 2020 21:53:41 -0400 Subject: [PATCH] fix: stop spinner before logging writes --- src/node/build/index.ts | 15 +++++++++++++++ src/node/cli.ts | 10 ---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/node/build/index.ts b/src/node/build/index.ts index 14fca6ec452c1c..32fda84080c18c 100644 --- a/src/node/build/index.ts +++ b/src/node/build/index.ts @@ -1,6 +1,7 @@ import path from 'path' import fs from 'fs-extra' import chalk from 'chalk' +import { Ora } from 'ora' import resolve from 'resolve-from' import { rollup as Rollup, RollupOutput, ExternalOption } from 'rollup' import { createResolver, supportedExts } from '../resolver' @@ -47,6 +48,7 @@ export async function build(options: BuildConfig = {}): Promise { }) } + const isTest = process.env.NODE_ENV === 'test' process.env.NODE_ENV = 'production' const start = Date.now() @@ -72,6 +74,17 @@ export async function build(options: BuildConfig = {}): Promise { sourcemap = false } = options + let spinner: Ora | undefined + const msg = 'Building for production...' + if (!silent) { + if (process.env.DEBUG || isTest) { + console.log(msg) + } else { + console.log(process.env.NODE_ENV) + spinner = require('ora')(msg + '\n').start() + } + } + const indexPath = path.resolve(root, 'index.html') const publicBasePath = base.replace(/([^/])$/, '$1/') // ensure ending slash const resolvedAssetsPath = path.join(outDir, assetsDir) @@ -171,6 +184,8 @@ export async function build(options: BuildConfig = {}): Promise { ...rollupOutputOptions }) + spinner && spinner.stop() + const indexHtml = emitIndex ? renderIndex(output, cssFileName) : '' if (write) { diff --git a/src/node/cli.ts b/src/node/cli.ts index f7f375c48a5143..149ec463ad0ccd 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -7,7 +7,6 @@ if (argv.debug) { import os from 'os' import chalk from 'chalk' -import { Ora } from 'ora' import { UserConfig, resolveConfig } from './config' function logHelp() { @@ -144,19 +143,10 @@ async function runServe( } async function runBuild(options: UserConfig) { - let spinner: Ora | undefined - const msg = 'Building for production...' - if (process.env.DEBUG || process.env.NODE_ENV === 'test') { - console.log(msg) - } else { - spinner = require('ora')(msg + '\n').start() - } try { await require('../dist').build(options) - spinner && spinner.stop() process.exit(0) } catch (err) { - spinner && spinner.stop() console.error(chalk.red(`[vite] Build errored out.`)) console.error(err) process.exit(1)