How to adjust the vite logger via config plugin?

1.7k Views Asked by At

I created a plugin that changes the vite config of the app that uses it. Everything works but the custom logger function - why?

Minimal example:

export default function plugin(opts: PluginOptions): Plugin {
  const logger = createLogger('info', {
      prefix: '',
  });

  return {
    name: 'vite-plugin',
    enforce: 'pre',
    config: () => ({
      server: {
        host: 'localhost',
      },
      customLogger: {
        ...logger,
        info: (msg: string, options?: LogOptions) => logger.info(msg.replace('A', 'B'), options),
      },
    }),
  };
}

If I insert the customLogger directly into the config of the app it works fine.

1

There are 1 best solutions below

2
On BEST ANSWER