forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mjs
125 lines (111 loc) · 3.47 KB
/
vite.config.mjs
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
// Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
/* eslint-disable security/detect-non-literal-fs-filename */
import { createRequire } from 'module'
import { defineConfig } from 'vite'
import VuePlugin from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'
import { resolve, dirname } from 'node:path'
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { homedir } from 'os'
import svgIconsPlugin from './app/frontend/build/iconsPlugin.mjs'
import ManualChunksPlugin from './app/frontend/build/manualChunks.mjs'
import tsconfig from './tsconfig.base.json' assert { type: 'json' }
const dir = dirname(fileURLToPath(import.meta.url))
const SSL_PATH = resolve(homedir(), '.localhost')
// eslint-disable-next-line sonarjs/cognitive-complexity
export default defineConfig(({ mode, command }) => {
const isTesting = ['test', 'cypress'].includes(mode)
const isBuild = command === 'build'
const require = createRequire(import.meta.url)
const plugins = [
VuePlugin({
template: {
compilerOptions: {
nodeTransforms:
isTesting || !!process.env.VITE_TEST_MODE
? []
: [require('./app/frontend/build/transforms/transformTestId.js')],
},
},
}),
svgIconsPlugin(),
]
if (!isTesting || isBuild) {
// Ruby plugin is not needed inside of the vitest context and has some side effects.
const { default: RubyPlugin } = require('vite-plugin-ruby')
plugins.push(RubyPlugin())
plugins.push(
...VitePWA({
disable: isTesting || !!process.env.VITE_TEST_MODE,
// should be generated on ruby side
manifest: false,
registerType: 'prompt',
srcDir: 'apps/mobile/sw',
filename: 'sw.ts',
includeManifestIcons: false,
injectRegister: null,
strategies: 'injectManifest',
}),
)
plugins.push(ManualChunksPlugin())
}
let https = false
// vite-ruby controlls this variable, it's either "true" or "false"
if (process.env.VITE_RUBY_HTTPS === 'true') {
const SSL_CERT = readFileSync(resolve(SSL_PATH, 'localhost.crt'))
const SSL_KEY = readFileSync(resolve(SSL_PATH, 'localhost.key'))
https = {
cert: SSL_CERT,
key: SSL_KEY,
}
}
let publicDir
if (!isBuild) {
publicDir = resolve(dir, 'public')
}
return {
publicDir,
esbuild: {
target: isTesting ? 'esnext' : tsconfig.compilerOptions.target,
},
resolve: {
alias: {
'^vue-easy-lightbox$':
'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.esm.min.js',
},
},
server: {
https,
watch: {
ignored: isTesting
? []
: [
'**/*.spec.*',
'**/__tests__/**/*',
(path) =>
!path.includes('app/frontend') ||
path.includes('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: process.env.CI ? 30_000 : 5_000,
unstubGlobals: true,
onConsoleLog(log) {
if (log.includes('Not implemented: navigation')) return false
},
},
plugins,
}
})