index.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import type { Plugin } from 'vite'
  2. import Components from 'unplugin-vue-components/vite'
  3. import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
  4. import vueSetupExtend from 'vite-plugin-vue-setup-extend'
  5. import vue from '@vitejs/plugin-vue'
  6. import vueJsx from '@vitejs/plugin-vue-jsx'
  7. import { configHtmlPlugin } from './html'
  8. // import { configMockPlugin } from './mock'
  9. import { configCompressPlugin } from './compress'
  10. export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean, prodMock) {
  11. const { VITE_USE_MOCK, VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE } = viteEnv
  12. const vitePlugins: (Plugin | Plugin[])[] = [
  13. // have to
  14. vue(),
  15. // have to
  16. vueJsx(),
  17. // 按需引入NaiveUi且自动创建组件声明
  18. Components({
  19. dts: true,
  20. resolvers: [NaiveUiResolver()]
  21. })
  22. ]
  23. // vite-plugin-html
  24. vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
  25. // vite-plugin-vue-setup-extend
  26. vitePlugins.push(vueSetupExtend())
  27. // vite-plugin-mock
  28. // VITE_USE_MOCK && vitePlugins.push(configMockPlugin(isBuild, prodMock))
  29. if (isBuild) {
  30. // rollup-plugin-gzip
  31. vitePlugins.push(
  32. configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
  33. )
  34. }
  35. return vitePlugins
  36. }