vite.config.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.base.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, command }) => {
  14. const isTesting = ['test', 'storybook', 'cypress'].includes(mode)
  15. const isBuild = command === 'build'
  16. return {
  17. esbuild: {
  18. target: tsconfig.compilerOptions.target,
  19. },
  20. resolve: {
  21. alias: {
  22. '@mobile': path.resolve(__dirname, 'app/frontend/apps/mobile'),
  23. '@shared': path.resolve(__dirname, 'app/frontend/shared'),
  24. '@tests': path.resolve(__dirname, 'app/frontend/tests'),
  25. '@stories': path.resolve(__dirname, 'app/frontend/stories'),
  26. '@cy': path.resolve(__dirname, '.cypress'),
  27. '@': path.resolve(__dirname, 'app/frontend'),
  28. },
  29. },
  30. define: {
  31. VITE_TEST_MODE: !!process.env.VITEST || !!process.env.VITE_TEST_MODE,
  32. },
  33. test: {
  34. globals: true,
  35. setupFiles: ['app/frontend/tests/vitest.setup.ts'],
  36. environment: 'jsdom',
  37. },
  38. plugins: [
  39. // Ruby plugin is not needed inside of the vitest context and has some side effects.
  40. isTesting && !isBuild ? [] : [...RubyPlugin(), ManualChunks()],
  41. VuePlugin({
  42. template: {
  43. compilerOptions: {
  44. nodeTransforms: isTesting ? [] : [TransformTestId],
  45. },
  46. },
  47. }),
  48. createSvgIconsPlugin({
  49. // Specify the icon folder to be cached
  50. iconDirs: [
  51. path.resolve(
  52. process.cwd(),
  53. `${
  54. mode === 'storybook' ? '../public' : 'public'
  55. }/assets/images/icons`,
  56. ),
  57. ],
  58. // Specify symbolId format
  59. symbolId: 'icon-[dir]-[name]',
  60. svgoOptions: {
  61. plugins: [
  62. { name: 'preset-default' },
  63. {
  64. name: 'removeAttributesBySelector',
  65. params: {
  66. selectors: [
  67. {
  68. selector: "[fill='#50E3C2']",
  69. attributes: 'fill',
  70. },
  71. // TODO: we need to add a own plugin or add some identifier to the svg files, to add the same functionality
  72. // like we have in the old gulp script (fill='#50E3C2'] + parent fill='none' should be removed).
  73. ],
  74. },
  75. },
  76. {
  77. name: 'convertColors',
  78. params: {
  79. currentColor: /(#BD0FE1|#BD10E0)/,
  80. },
  81. },
  82. ],
  83. } as OptimizeOptions,
  84. }),
  85. ],
  86. }
  87. })