plugins.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { cdn } from './cdn'
  2. import vue from '@vitejs/plugin-vue'
  3. import { viteBuildInfo } from './info'
  4. import svgLoader from 'vite-svg-loader'
  5. import vueJsx from '@vitejs/plugin-vue-jsx'
  6. // import { viteMockServe } from 'vite-plugin-mock'
  7. import { configCompressPlugin } from './compress'
  8. // import ElementPlus from "unplugin-element-plus/vite";
  9. import { visualizer } from 'rollup-plugin-visualizer'
  10. import removeConsole from 'vite-plugin-remove-console'
  11. import { themePreprocessorPlugin } from '@pureadmin/theme'
  12. import { genScssMultipleScopeVars } from '../src/layout/theme'
  13. export function getPluginsList(
  14. command: string,
  15. VITE_CDN: boolean,
  16. VITE_COMPRESSION: ViteCompression
  17. ) {
  18. const prodMock = false
  19. const lifecycle = process.env.npm_lifecycle_event
  20. return [
  21. vue(),
  22. // jsx、tsx语法支持
  23. vueJsx(),
  24. VITE_CDN ? cdn : null,
  25. configCompressPlugin(VITE_COMPRESSION),
  26. // 线上环境删除console
  27. removeConsole({ external: ['src/assets/iconfont/iconfont.js'] }),
  28. viteBuildInfo(),
  29. // 自定义主题
  30. themePreprocessorPlugin({
  31. scss: {
  32. multipleScopeVars: genScssMultipleScopeVars(),
  33. extract: true
  34. }
  35. }),
  36. // svg组件化支持
  37. svgLoader(),
  38. // ElementPlus({}),
  39. // mock支持
  40. // viteMockServe({
  41. // mockPath: 'mock',
  42. // localEnabled: command === 'serve',
  43. // prodEnabled: command !== 'serve' && prodMock,
  44. // injectCode: `
  45. // import { setupProdMockServer } from './mockProdServer';
  46. // setupProdMockServer();
  47. // `,
  48. // logger: false
  49. // }),
  50. // 打包分析
  51. lifecycle === 'report'
  52. ? visualizer({ open: true, brotliSize: true, filename: 'report.html' })
  53. : null
  54. ]
  55. }