Repository: nuxt/nuxt
File: packages/vite/src/client.ts (TypeScript)

Code before:
      ModulePreloadPolyfillPlugin(),
      // ensure changes in chunks do not invalidate whole build
      StableEntryPlugin(nuxt),
      AnalyzePlugin(nuxt),
      DevServerPlugin(nuxt),
      VitePluginCheckerPlugin(nuxt, 'client'),
    ],
    appType: 'custom',
    server: {
      warmup: {
        clientFiles: [ctx.entry],
      },
      middlewareMode: true,
    },
    ...clientEnvironment(nuxt, ctx.entry),
  } satisfies vite.InlineConfig, nuxt.options.vite.$client || {}))

  clientConfig.customLogger = createViteLogger(clientConfig)

  await nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })

  // Add transpile packages to optimizeDeps.exclude to prevent Vite from optimizing them at runtime
  // This must happen after vite:extendConfig since modules may add transpile entries asynchronously
  clientConfig.optimizeDeps ||= {}
  clientConfig.optimizeDeps.exclude ||= []
  const transpilePatterns = getTranspilePatterns({ isDev: nuxt.options.dev, isClient: true })
  clientConfig.optimizeDeps.exclude.push(...transpilePatterns)

  clientConfig.plugins!.unshift(
    vuePlugin(clientConfig.vue),
    viteJsxPlugin(clientConfig.vueJsx),
  )

  await nuxt.callHook('vite:configResolved', clientConfig, { isClient: true, isServer: false })

  if (nuxt.options.dev) {
    // Dev
    const viteServer = await vite.createServer(clientConfig)
    ctx.clientServer = viteServer
    nuxt.hook('close', () => viteServer.close())
    await nuxt.callHook('vite:serverCreated', viteServer, { isClient: true, isServer: false })
  } else {
    // Build
    logger.info('Building client...')
    const start = Date.now()
    logger.restoreAll()
    await vite.build(clientConfig)
    logger.wrapAll()
    await nuxt.callHook('vite:compiled')
    logger.success(`Client built in ${Date.now() - start}ms`)
  }

Review comment (refactor):
we should probably _only_ inject them here, as otherwise we'll likely have duplicates.

Code after:
      // ensure changes in chunks do not invalidate whole build
      StableEntryPlugin(nuxt),
      AnalyzePlugin(nuxt),
      DevServerPlugin(nuxt),
      VitePluginCheckerPlugin(nuxt, 'client'),
    ],
    appType: 'custom',
    server: {
      warmup: {
        clientFiles: [ctx.entry],
      },
      middlewareMode: true,
    },
    ...clientEnvironment(nuxt, ctx.entry),
  } satisfies vite.InlineConfig, nuxt.options.vite.$client || {}))

  clientConfig.customLogger = createViteLogger(clientConfig)

  await nuxt.callHook('vite:extendConfig', clientConfig, { isClient: true, isServer: false })

  clientConfig.plugins!.unshift(
    vuePlugin(clientConfig.vue),
    viteJsxPlugin(clientConfig.vueJsx),
  )

  await nuxt.callHook('vite:configResolved', clientConfig, { isClient: true, isServer: false })

  if (nuxt.options.dev) {
    // Dev
    const viteServer = await vite.createServer(clientConfig)
    ctx.clientServer = viteServer
    nuxt.hook('close', () => viteServer.close())
    await nuxt.callHook('vite:serverCreated', viteServer, { isClient: true, isServer: false })
  } else {
    // Build
    logger.info('Building client...')
    const start = Date.now()
    logger.restoreAll()
    await vite.build(clientConfig)
    logger.wrapAll()
    await nuxt.callHook('vite:compiled')
    logger.success(`Client built in ${Date.now() - start}ms`)
  }
}