-
Notifications
You must be signed in to change notification settings - Fork 9
/
vite.config.ts
131 lines (107 loc) · 3.04 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
129
130
131
/// <reference types="vite/client" />
import type { CollectionValues } from '@getodk/common/types/collections/CollectionValues';
import { resolve as resolvePath } from 'node:path';
import dts from 'vite-plugin-dts';
import { defineConfig } from 'vitest/config';
const supportedBrowsers = new Set(['chromium', 'firefox', 'webkit'] as const);
type SupportedBrowser = CollectionValues<typeof supportedBrowsers>;
const isSupportedBrowser = (browserName: string): browserName is SupportedBrowser =>
supportedBrowsers.has(browserName as SupportedBrowser);
const BROWSER_NAME = (() => {
const envBrowserName = process.env.BROWSER_NAME;
if (envBrowserName == null) {
return null;
}
if (isSupportedBrowser(envBrowserName)) {
return envBrowserName;
}
throw new Error(`Unsupported browser: ${envBrowserName}`);
})();
const BROWSER_ENABLED = BROWSER_NAME != null;
const TEST_ENVIRONMENT = BROWSER_ENABLED ? 'node' : 'jsdom';
export default defineConfig(({ mode }) => {
const { VITE_BUILD_TARGET } = process.env;
const IS_SOLID_BUILD_TARGET = VITE_BUILD_TARGET === 'solid';
const isTest = mode === 'test';
const entry = './src/index.ts';
const entryKey = IS_SOLID_BUILD_TARGET ? 'solid' : 'index';
const libEntry = {
[entryKey]: entry,
};
const entries = Object.values(libEntry);
const external = ['@getodk/common'];
if (IS_SOLID_BUILD_TARGET) {
external.push('solid-js', 'solid-js/store');
}
const dtsPlugins = IS_SOLID_BUILD_TARGET
? []
: [
dts({
entryRoot: './src',
exclude: ['@getodk/common', 'test', 'vite-env.d.ts'],
include: ['src/**/*.ts'],
}),
];
return {
build: {
target: 'esnext',
minify: false,
sourcemap: true,
emptyOutDir: false,
outDir: './dist',
manifest: true,
lib: {
entry: libEntry,
formats: ['es'],
name: '@getodk/xforms-engine',
fileName(_, entryName) {
if (entryName in libEntry) {
return `${entryName}.js`;
}
return entryName.replace(/^\.src\//, '').replace(/\.ts$/, '.js');
},
},
rollupOptions: { external },
},
esbuild: {
target: 'esnext',
format: 'esm',
exclude: external,
},
optimizeDeps: {
esbuildOptions: {
target: 'esnext',
},
entries,
include: ['@getodk/xpath'],
force: true,
},
plugins: [...dtsPlugins],
resolve: {
alias: {
'@getodk/common/types': resolvePath(__dirname, '../common/types'),
'@getodk/common': resolvePath(__dirname, '../common/src'),
},
// prettier-ignore
conditions:
isTest
// Without this, anything using Solid reactivity fails inexplicably...
? ['solid', 'development', 'browser']
: ['solid', 'import', 'browser'],
},
test: {
browser: {
enabled: BROWSER_ENABLED,
name: BROWSER_NAME!,
provider: 'playwright',
headless: true,
screenshotFailures: false,
},
environment: TEST_ENVIRONMENT,
globals: false,
include: ['src/**/*.test.ts', 'test/**/*.test.ts'],
exclude: ['src/**/*.tsx', 'test/**/*.tsx'],
reporters: process.env.GITHUB_ACTIONS ? ['default', 'github-actions'] : 'default',
},
};
});