forked from kyma-project/busola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.mts
84 lines (78 loc) · 1.99 KB
/
vite.config.mts
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
/// <reference types="vitest/config" />
import { defineConfig, transformWithEsbuild } from 'vite';
import viteTsconfigPaths from 'vite-tsconfig-paths';
import svgr from 'vite-plugin-svgr';
import react from '@vitejs/plugin-react';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import eslint from 'vite-plugin-eslint';
import fs from 'fs';
import glob from 'glob';
// https://vitejs.dev/config/
export default defineConfig({
build: {
outDir: 'build',
},
server: {
port: 8080,
},
plugins: [
{
name: 'treat-js-files-as-jsx',
async transform(code, id) {
if (!id.match(/src\/.*\.js$/)) return null;
// Use the exposed transform from vite, instead of directly
// transforming with esbuild
return transformWithEsbuild(code, id, {
loader: 'jsx',
jsx: 'automatic',
});
},
},
react(),
viteTsconfigPaths(),
svgr({
include: '**/*.svg?react',
}),
viteStaticCopy({
targets: [
{
src: 'resources/base/resource-validation/rule-sets/**/*.yaml',
dest: 'resource-validation',
rename: 'rule-set.yaml',
transform() {
return mergeYamlFiles('resources/base/resource-validation/rule-sets/**/*.yaml');
},
},
],
}),
eslint()
],
worker: {
plugins: () => [viteTsconfigPaths()],
},
optimizeDeps: {
force: true,
esbuildOptions: {
loader: {
'.js': 'jsx',
},
},
include: [
'@openapi-contrib/openapi-schema-to-json-schema',
'@stoplight/json-ref-resolver',
'monaco-yaml/yaml.worker.js'
]
},
define: {
'process.env.IS_DOCKER': JSON.stringify(process.env.IS_DOCKER || false),
},
});
function mergeYamlFiles (filesPath) {
let mergedYamlContent = '';
const files = glob.sync(filesPath);
files.forEach(file => {
const content = fs.readFileSync(file, 'utf-8');
mergedYamlContent += `---\n${content}\n`;
});
return mergedYamlContent;
}