-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.ts
More file actions
47 lines (46 loc) · 1.47 KB
/
vite.config.ts
File metadata and controls
47 lines (46 loc) · 1.47 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
import { defineConfig } from 'vite';
import mix from 'vite-plugin-mix';
import fg from 'fast-glob';
import path from 'path';
import { renderWithConfig as renderWithFrontendConfig } from './src/config/frontend';
import { getConfig as getBackendConfig } from './src/config/backend';
const root = process.cwd();
const publicMyOpenVdpPath = path.resolve(path.join(root, 'public', 'my-open-vdp'));
export default defineConfig(async (env) => {
const publicMyOpenVdpFiles = await fg('*', { cwd: publicMyOpenVdpPath });
if (!publicMyOpenVdpFiles.length) {
throw new Error(
`MyOpenVDP files missing in ${publicMyOpenVdpPath}. Please build ../ui before building this project. (cd ../ui ; yarn build)`
);
}
return {
plugins: [
{
name: 'check-backend-config',
apply: 'serve',
configureServer(devServer) {
try {
getBackendConfig();
} catch (e) {
devServer.config.logger.error('bad backend configuration.', {
timestamp: true,
});
console.error(e);
devServer.middlewares.use((_request, response) => {
response.end(`Bad backend configuration: ${e as string}`);
});
}
},
},
{
name: 'index-html-replace-frontend-config-serve',
apply: 'serve',
enforce: 'pre',
transformIndexHtml: renderWithFrontendConfig,
},
mix({
handler: './src/api.ts',
}),
],
};
});