javascripttypescriptvitevite-plugin-development

How to adjust the vite logger via config plugin?


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.


Solution

  • It's a bug and has been fixed in Vite 4.