unjs / nitro

Next Generation Server Toolkit. Create web servers with everything you need and deploy them wherever you prefer.
https://nitro.unjs.io
MIT License
5.92k stars 497 forks source link

use full build of consola for development time #1991

Closed pi0 closed 8 months ago

pi0 commented 9 months ago

Context: https://github.com/unjs/nitro/issues/1761

We automatically use lighter build of consola for production but for development, we can keep using fancy logger.

XStarlink commented 7 months ago

@cany748 Thanks a lot for the fix!

I'm trying to import consola to log requests received by nitro but I still have an unformatted version of consola, what's the right way to import it?

For now I'm doing it this way:

import { consola } from 'consola'

consola.box({
  title: `Request at ${time}`,
  message: `[${event.method}] ${event.path}`
})

Thanks in advance for your advice

cany748 commented 7 months ago

@cany748 Thanks a lot for the fix!

I'm trying to import consola to log requests received by nitro but I still have an unformatted version of consola, what's the right way to import it?

For now I'm doing it this way:

import { consola } from 'consola'

consola.box({
  title: `Request at ${time}`,
  message: `[${event.method}] ${event.path}`
})

Thanks in advance for your advice

Do you need the full version of consola in production mode? Try this:

// nitro.config.ts
export default defineNitroConfig({
  imports: { imports: [{ name: "consola", from: "consola" }] },
  unenv: { alias: { consola: "consola" } },
});

And use the auto-imported consola.

XStarlink commented 7 months ago

@cany748 Thanks a lot for the fix! I'm trying to import consola to log requests received by nitro but I still have an unformatted version of consola, what's the right way to import it? For now I'm doing it this way:

import { consola } from 'consola'

consola.box({
  title: `Request at ${time}`,
  message: `[${event.method}] ${event.path}`
})

Thanks in advance for your advice

Do you need the full version of consola in production mode? Try this:

// nitro.config.ts
export default defineNitroConfig({
  imports: { imports: [{ name: "consola", from: "consola" }] },
  unenv: { alias: { consola: "consola" } },
});

And use the auto-imported consola.

@cany748 Thank you very much, it works! (I had to put this config in the nitro key of nuxt.config.ts because nuxt warned me that nitro.config.ts cannot be used with nuxt)

I only need consola in dev, will this method be only effetive in dev or also in production (after build)?

I have a second question, why do we have to add these options to access consola when you've made the fix above which seemed to no longer mock the full build of consola in dev?

cany748 commented 7 months ago

I only need consola in dev, will this method be only effetive in dev or also in production (after build)?

The full version of consola will be available in Production mode

I have a second question, why do we have to add these options to access consola when you've made the fix above which seemed to no longer mock the full build of consola in dev?

try updating the dependencies