Tips for module authors

You can start adding experimental vite support to your modules, considering there are known issues and potential breaking changes.

Here are some tips:

  • Avoid depending on webpack features (like loaders) as much as possible
  • Avoid depending on vite plugins that do not have webpack alternative since we still use webpack for production build
  • Avoid directly depending on either webpack or vite, but if had to, consider supporting both
  • Extend nuxt build options like alias and build.transpile in your modules. This way nuxt can do bundler-level config based on generic options

Hooks

You can either extend vite config by extending nuxt.options.vite in module or using hooks

vite:extend

nuxt.hook('vite:extend', ({ config, nuxt, builder }) => { })

Called one time with vite context and default shared config merged with user config

vite:extendConfig

nuxt.hook('vite:extendConfig', (config, { isClient, isServer }) => { })

Called two times. Once with resolved client config and once with resolved server config. Use it to apply client/server specific extension.

vite:serverCreated

nuxt.hook('vite:serverCreated', (viteServer) => { })

Called one time with vite server once it has been created.

Edit this page on GitHub Updated at Mon, Oct 11, 2021