vite.config.ts 2.9 KB

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