forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.mjs
More file actions
199 lines (181 loc) · 6.3 KB
/
vite.config.mjs
File metadata and controls
199 lines (181 loc) · 6.3 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
// Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
/// <reference types="vitest/config" />
import { createRequire } from 'module'
import { readFileSync } from 'node:fs'
import { resolve, dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { homedir } from 'os'
import tailwindcss from '@tailwindcss/vite'
import VuePlugin from '@vitejs/plugin-vue'
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
import svgIconsPlugin from './app/frontend/build/iconsPlugin.mjs'
const dir = dirname(fileURLToPath(import.meta.url))
const SSL_PATH = resolve(homedir(), '.local/state/localhost.rb')
const isEnvBooleanSet = (value) => ['true', '1'].includes(value)
export default defineConfig(({ mode, command }) => {
const isTesting = ['test', 'cypress'].includes(mode)
const isBuild = command === 'build'
const require = createRequire(import.meta.url)
const plugins = [
tailwindcss(),
VuePlugin({
template: {
compilerOptions: {
nodeTransforms:
isTesting || isEnvBooleanSet(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 || isEnvBooleanSet(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',
}),
)
}
let https = false
// vite-ruby controlls this variable, it's either "true" or "false"
if (isEnvBooleanSet(process.env.VITE_RUBY_HTTPS)) {
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: {
// TODO: Remove the following line once the related upstream TailwindCSS issue has been addressed,
// since it can mask potential syntax errors.
// https://github.com/tailwindlabs/tailwindcss/issues/16582
logOverride: { 'css-syntax-error': 'silent' },
},
build: {
rollupOptions: {
output: {
manualChunks: {
lodash: ['lodash-es'],
vue: ['vue', 'vue-router', 'pinia'],
datepicker: ['@vuepic/vue-datepicker'],
linkifyjs: ['linkifyjs', 'linkify-string'],
graphql: [
'graphql',
// 🚨 'graphql-ruby-client',
// Important: don't include the package root here, it pulls in the Node-only `sync` entry
// which imports fs/path/crypto/http/... and triggers Vite "externalized for browser" warnings.
'graphql-ruby-client/subscriptions/ActionCableLink',
'graphql-tag',
'@apollo/client',
'@vue/apollo-composable',
'@rails/actioncable',
],
formkit: [
'@formkit/core',
'@formkit/dev',
// '@formkit/drag-and-drop', # is not used in mobile
'@formkit/i18n',
'@formkit/inputs',
'@formkit/rules',
'@formkit/tailwindcss',
'@formkit/themes',
'@formkit/utils',
'@formkit/validation',
'@formkit/vue',
],
},
},
},
},
resolve: {
preserveSymlinks: isEnvBooleanSet(process.env.PRESERVE_SYMLINKS),
alias: {
'^vue-easy-lightbox$': 'vue-easy-lightbox/dist/external-css/vue-easy-lightbox.esm.min.js',
// In non-test builds, alias fake-timers to a tiny shim so Vite doesn't resolve Node core deps
...(isTesting
? {}
: {
'@sinonjs/fake-timers': resolve(dir, 'app/frontend/build/shims/fake-timers.ts'),
}),
},
},
server: {
https,
watch: {
ignored: isTesting
? []
: [
'**/*.spec.*',
'**/__tests__/**/*',
(path) => !path.includes('app/frontend') || path.includes('frontend/tests'),
],
},
},
define: {
VITE_TEST_MODE:
isEnvBooleanSet(process.env.VITEST) || isEnvBooleanSet(process.env.VITE_TEST_MODE),
},
test: {
globals: true,
// narrowing down test folder speeds up fast-glob in Vitest
root: './app/frontend',
setupFiles: ['./tests/vitest.setup.ts'],
environment: 'jsdom',
clearMocks: true,
css: false,
testTimeout: isEnvBooleanSet(process.env.CI) ? 30_000 : 5_000,
unstubGlobals: true,
onConsoleLog(log) {
if (
log.includes('Not implemented: navigation') ||
log.includes('<Suspense> is an experimental feature')
)
return false
},
// perf improvements
server: {
deps: {
// vue-datepicker imports from date-fns and we don't want it to import ES version
inline: ['@vuepic/vue-datepicker'],
},
},
alias: [
// ESM version of date-fns exports a lot of extra files which takes 500ms to load on M4 Mac
// CJS version takes ~175ms which is also a lot, but not as much
{
find: /^date-fns$/,
replacement: join(dirname(require.resolve('date-fns/package.json')), 'index.cjs'),
},
],
experimental: {
// persistent cache between reruns, invalidates if any dependency is updated
// vitest doesn't cache files with `import.meta.glob` inside, so it might be a good
// idea to put them all inside as few files as possible just for a small perf boost
// the perf difference is noticible when running a single/a few tests, but has
// negligible impact when running the whole suite due to parallelisation
fsModuleCache: true,
},
},
plugins,
}
})