vite.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. /* eslint-disable no-restricted-imports */
  3. /// <reference types="vitest" />
  4. import { defineConfig } from 'vite'
  5. import RubyPlugin from 'vite-plugin-ruby'
  6. import VuePlugin from '@vitejs/plugin-vue'
  7. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  8. import type { OptimizeOptions } from 'svgo'
  9. import * as path from 'path'
  10. import tsconfig from './tsconfig.json'
  11. import TransformTestId from './app/frontend/build/transforms/transformTestId'
  12. import ManualChunks from './app/frontend/build/manual-chunks.mjs'
  13. export default defineConfig(({ mode }) => {
  14. const isTesting = ['test', 'storybook'].includes(mode)
  15. return {
  16. esbuild: {
  17. target: tsconfig.compilerOptions.target,
  18. },
  19. resolve: {
  20. alias: {
  21. '@mobile': path.resolve(__dirname, 'app/frontend/apps/mobile'),
  22. '@shared': path.resolve(__dirname, 'app/frontend/shared'),
  23. '@tests': path.resolve(__dirname, 'app/frontend/tests'),
  24. '@stories': path.resolve(__dirname, 'app/frontend/stories'),
  25. '@': path.resolve(__dirname, 'app/frontend'),
  26. },
  27. },
  28. define: {
  29. VITE_TEST_MODE: !!process.env.VITEST || !!process.env.VITE_TEST_MODE,
  30. },
  31. test: {
  32. globals: true,
  33. setupFiles: ['app/frontend/tests/vitest.setup.ts'],
  34. environment: 'jsdom',
  35. },
  36. plugins: [
  37. // Ruby plugin is not needed inside of the vitest context and has some side effects.
  38. isTesting ? [] : [...RubyPlugin(), ManualChunks()],
  39. VuePlugin({
  40. template: {
  41. compilerOptions: {
  42. nodeTransforms: isTesting ? [] : [TransformTestId],
  43. },
  44. },
  45. }),
  46. createSvgIconsPlugin({
  47. // Specify the icon folder to be cached
  48. iconDirs: [
  49. path.resolve(
  50. process.cwd(),
  51. `${
  52. mode === 'storybook' ? '../public' : 'public'
  53. }/assets/images/icons`,
  54. ),
  55. ],
  56. // Specify symbolId format
  57. symbolId: 'icon-[dir]-[name]',
  58. svgoOptions: {
  59. plugins: [
  60. { name: 'preset-default' },
  61. {
  62. name: 'removeAttributesBySelector',
  63. params: {
  64. selectors: [
  65. {
  66. selector: "[fill='#50E3C2']",
  67. attributes: 'fill',
  68. },
  69. // TODO: we need to add a own plugin or add some identifier to the svg files, to add the same functionality
  70. // like we have in the old gulp script (fill='#50E3C2'] + parent fill='none' should be removed).
  71. ],
  72. },
  73. },
  74. {
  75. name: 'convertColors',
  76. params: {
  77. currentColor: /(#BD0FE1|#BD10E0)/,
  78. },
  79. },
  80. ],
  81. } as OptimizeOptions,
  82. }),
  83. ],
  84. }
  85. })