vite.config.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. /// <reference types="vitest" />
  3. import { defineConfig } from 'vite'
  4. import RubyPlugin from 'vite-plugin-ruby'
  5. import VuePlugin from '@vitejs/plugin-vue'
  6. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  7. import type { OptimizeOptions } from 'svgo'
  8. import * as path from 'path'
  9. export default defineConfig(({ mode }) => ({
  10. esbuild: {
  11. target: 'es2020', // Must stay in sync with tsconfig.json.
  12. },
  13. resolve: {
  14. alias: {
  15. '@mobile': path.resolve(__dirname, 'app/frontend/apps/mobile'),
  16. '@common': path.resolve(__dirname, 'app/frontend/common'),
  17. '@tests': path.resolve(__dirname, 'app/frontend/tests'),
  18. '@': path.resolve(__dirname, 'app/frontend'),
  19. },
  20. },
  21. define: {
  22. VITE_TEST_MODE: !!process.env.VITEST || !!process.env.VITE_TEST_MODE,
  23. },
  24. test: {
  25. globals: true,
  26. setupFiles: ['app/frontend/tests/vitest.setup.ts'],
  27. environment: 'jsdom',
  28. },
  29. plugins: [
  30. // Ruby plugin is not needed inside of the vitest context and has some side effects.
  31. ['test', 'storybook'].includes(mode) ? [] : RubyPlugin(),
  32. VuePlugin(),
  33. createSvgIconsPlugin({
  34. // Specify the icon folder to be cached
  35. iconDirs: [
  36. path.resolve(
  37. process.cwd(),
  38. `${
  39. mode === 'storybook' ? '../public' : 'public'
  40. }/assets/images/icons`,
  41. ),
  42. ],
  43. // Specify symbolId format
  44. symbolId: 'icon-[dir]-[name]',
  45. svgoOptions: {
  46. plugins: [
  47. { name: 'preset-default' },
  48. {
  49. name: 'removeAttributesBySelector',
  50. params: {
  51. selectors: [
  52. {
  53. selector: "[fill='#50E3C2']",
  54. attributes: 'fill',
  55. },
  56. {
  57. selector: "[fill='#BD0FE1']",
  58. attributes: 'fill',
  59. },
  60. {
  61. selector: "[fill='#BD10E0']",
  62. attributes: 'fill',
  63. },
  64. ],
  65. },
  66. },
  67. ],
  68. } as OptimizeOptions,
  69. }),
  70. ],
  71. }))