vite icon indicating copy to clipboard operation
vite copied to clipboard

clearScreen: 'update'

Open Rich-Harris opened this issue 2 years ago • 0 comments

Description

If a plugin logs something to the console, the logs are destroyed as soon as the welcome text appears...

  VITE v3.0.0  ready in 243 ms

  ➜  Local:   http://127.0.0.1:5174/
  ➜  Network: use --host to expose

...unless you use clearScreen: false — in other words, potentially critical logs are hidden by default. Of course, there's a good reason why clearScreen: true is the default; setting it to false is often undesirable.

It's possible to work around this — in SvelteKit we're doing this...

const print_urls = vite.printUrls;
vite.printUrls = function () {
  print_urls.apply(this);
  if (deferred_warning) console.error('\n' + deferred_warning);
};

...but that only works for that deferred_warning; adding new stuff involves more plumbing, and can never cover arbitrary other plugins unless we monkey-patch console which is brittle and hacky. It's also clearly not an individual plugin's responsibility.

Suggested solution

It would be nice if we had a hybrid solution — don't clear the screen initially, but do clear it after updates. Something like this:

clearScreen: 'update'

I'd personally love it if this was the default, and I'd go so far as to argue that it's not a breaking change, though others might feel differently about that last part.

Alternative

The name 'update' is definitely bikesheddable.

Additional context

No response

Validations

Rich-Harris avatar Jul 26 '22 14:07 Rich-Harris