forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
128 lines (118 loc) · 3.9 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
import { createRequire } from 'module'
import { defineConfig, type ResolvedConfig } from 'vite'
import VuePlugin from '@vitejs/plugin-vue'
import {
createSvgIconsPlugin,
type ViteSvgIconsPlugin,
} from 'vite-plugin-svg-icons'
import path from 'path'
import tsconfig from './tsconfig.base.json'
export default defineConfig(({ mode, command }) => {
const isStory = Boolean(process.env.HISTOIRE)
const isTesting = ['test', 'cypress'].includes(mode) || isStory
const isBuild = command === 'build' && !isStory
const require = createRequire(import.meta.url)
const svgPlugin = createSvgIconsPlugin({
// Specify the icon folder to be cached
iconDirs: [path.resolve(__dirname, `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 ViteSvgIconsPlugin['svgoOptions'],
})
if (isStory) {
// paching svg plugin for stories, because it's not working with ssr
const svgConfigResolved = svgPlugin.configResolved as (
cfg: ResolvedConfig,
) => void
svgConfigResolved({ command: 'build' } as ResolvedConfig)
delete svgPlugin.configResolved
const { load } = svgPlugin
svgPlugin.load = function fakeLoad(id) {
// @ts-expect-error the plugin is not updated
return load?.call(this, id, true)
}
}
const plugins = [
VuePlugin({
template: {
compilerOptions: {
nodeTransforms:
isTesting || !!process.env.VITE_TEST_MODE
? []
: [require('./app/frontend/build/transforms/transformTestId')],
},
},
}),
svgPlugin,
]
// Ruby plugin is not needed inside of the vitest context and has some side effects.
if (!isTesting || isBuild) {
const { default: RubyPlugin } = require('vite-plugin-ruby')
// const ManualChunks = require('./app/frontend/build/manualChunks')
plugins.push(RubyPlugin())
// TODO: Disable manual chunks for now, check if it's still neded with Vite 3.0.
// plugins.push(ManualChunks())
}
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'),
'^vue-easy-lightbox$':
'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.esm.min.js',
},
},
server: {
watch: {
ignored: isTesting
? []
: ['**/*.spec.*', '**/__tests__/**/*', 'app/frontend/tests/**/*'],
},
},
define: {
VITE_TEST_MODE: !!process.env.VITEST || !!process.env.VITE_TEST_MODE,
},
test: {
globals: true,
// narrowing down test folder speeds up fast-glob in Vitest
dir: 'app/frontend',
setupFiles: ['app/frontend/tests/vitest.setup.ts'],
environment: 'jsdom',
clearMocks: true,
css: false,
testTimeout: 30_000,
},
plugins,
}
})