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