Repository navigation
Expand file tree
/
Copy pathvite.config.js
More file actions
128 lines (124 loc) · 3.83 KB
/
Copy pathvite.config.js
File metadata and controls
128 lines (124 loc) · 3.83 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
/// <reference types="vitest" />
import { execSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { sveltekit } from '@sveltejs/kit/vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';
import arkenv from 'arkenv';
import { type } from 'arktype';
import postcssPresetEnv from 'postcss-preset-env';
import icons from 'unplugin-icons/vite';
import { analyzer } from 'vite-bundle-analyzer';
import crossOriginIsolation from 'vite-plugin-cross-origin-isolation';
import mkcert from 'vite-plugin-mkcert';
import { defineConfig } from 'vitest/config';
import { wuchale } from 'wuchale/vite';
const env = arkenv(
{
GITHUB_ACTIONS: 'boolean = false',
BUNDLE_ANALYZER: type
.enumerated('json', 'server', 'static')
.array()
.default(() => []),
VITEST: 'boolean = false',
HTTPS_DEV: 'boolean = false',
DEBUG: type('string|boolean').pipe(Boolean).default(false),
/** Required for mobile app, since window.location.origin returns localhost */
WEB_ORIGIN: 'string.url = "https://cigaleapp.github.io"',
BUILTIN_PROTOCOLS: type('string.url')
.array()
.default(() => [
'https://raw.githubusercontent.com/cigaleapp/cigale/main/protocols/insecta.cigaleprotocol.yaml',
'https://raw.githubusercontent.com/cigaleapp/cigale/main/protocols/entomoscope.cigaleprotocol.yaml',
'https://raw.githubusercontent.com/cigaleapp/cigale/main/examples/arthropods.cigaleprotocol.json',
'https://raw.githubusercontent.com/cigaleapp/cigale/main/protocols/idmybee.cigaleprotocol.json',
]),
},
{
arrayFormat: 'comma',
}
);
const prNumber = process.env.PR_NUMBER ? parseInt(process.env.PR_NUMBER, 10) : undefined;
export default defineConfig({
legacy: {
// FIXME: Needed for natural-regex
inconsistentCjsInterop: true,
},
test: {
environment: 'jsdom',
include: [
'src/lib/**/*.test{.svelte,}.{js,ts}',
'src/routes/**/*.test{.svelte,}.{js,ts}',
'src/routes/**/utils.js',
],
includeSource: [
'src/lib/**/*{.svelte,}.{js,ts}',
'scripts/generate-json-schemas.js',
'src/routes/**/utils.js',
],
reporters: env.GITHUB_ACTIONS ? ['dot', 'github-actions', 'html'] : ['default'],
globalSetup: './vitest-timezone.js',
setupFiles: ['@vitest/web-worker', './vitest-setup.js'],
coverage: {
reporter: ['json-summary', 'json', 'html'],
reportOnFailure: true,
include: ['src/lib/**/*{.svelte,}.{js,ts}', 'src/routes/**/utils.js'],
},
},
server: {
// Custom DNS to network-local IP address
// to have network-local https via mkcert
allowedHosts: ['stealth.local'],
fs: {
allow: ['./bun.lock'],
},
},
define: {
'import.meta.vitest': 'undefined',
'import.meta.env.buildCommit': JSON.stringify(
execSync('git rev-parse HEAD').toString().trim()
),
'import.meta.env.previewingPrNumber': prNumber ?? 'null',
'import.meta.env.builtinProtocols': JSON.stringify(env.BUILTIN_PROTOCOLS),
'import.meta.env.webOrigin': JSON.stringify(env.WEB_ORIGIN),
'import.meta.env.androidNativeCodeVersion': JSON.stringify(
readFileSync('android/.native-code-version', {
encoding: 'utf8',
})
),
},
worker: {
format: 'es',
plugins: () => [svelte()],
},
resolve: env.VITEST ? { conditions: ['browser'] } : {},
assetsInclude: ['**/*.wasm'],
optimizeDeps: {
exclude: ['onnxruntime-web', 'turbo_exif', 'fetch-progress', 'libraw-wasm'],
},
build: {
minify: !env.DEBUG,
sourcemap: env.DEBUG ? 'inline' : false,
},
css: {
postcss: {
plugins: [postcssPresetEnv({ browsers: 'baseline widely available, >1%' })],
},
},
plugins: [
...env.BUNDLE_ANALYZER.map((mode) =>
analyzer({
analyzerMode: mode,
openAnalyzer: false,
})
),
icons({
compiler: 'svelte',
defaultClass: 'icon',
}),
// FIXME Wuchale doesnt play well with Vitest for now
env.VITEST ? undefined : wuchale(),
sveltekit(),
crossOriginIsolation(),
env.HTTPS_DEV ? mkcert() : undefined,
],
});