-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
110 lines (105 loc) · 2.73 KB
/
vite.config.ts
File metadata and controls
110 lines (105 loc) · 2.73 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
import react from '@vitejs/plugin-react';
import fs from 'fs';
import path from 'path';
import checker from 'vite-plugin-checker';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';
import publicManifest from './public/manifest.json';
import { setupRyuuProxy } from './setupProxy';
export const buildDir = 'build';
export const tmpDir = '.tmp';
export const envPrefix = 'DOMO_';
interface ConfigInput {
command: 'build' | 'serve';
mode: string;
}
// https://vitejs.dev/config/
export default defineConfig(({ command }: ConfigInput) => {
let manifest = publicManifest;
const tmpManifestPath = path.join(process.cwd(), tmpDir, 'manifest.json');
try {
const tmpManifestContent = fs.readFileSync(tmpManifestPath, 'utf-8');
manifest = JSON.parse(tmpManifestContent);
} catch {
// Using default manifest when temp manifest is not available
}
return {
plugins: [
react(),
checker({
typescript: true,
eslint: {
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
useFlatConfig: true,
dev: {
logLevel: ['error'],
},
},
}),
tsconfigPaths(),
{
name: 'html-transform',
transformIndexHtml(html: string) {
return html.replace(
/<title>(.*?)<\/title>/,
`<title>${manifest.name}@${manifest.version}</title>`,
);
},
},
{
name: 'build-index',
async writeBundle() {
try {
if (command === 'build') {
const buildManifestPath = path.join(
process.cwd(),
buildDir,
'manifest.json',
);
fs.renameSync(tmpManifestPath, buildManifestPath);
}
} catch (error) {
console.warn('Could not replace "manifest.json" in build folder:', error);
}
},
},
{
name: 'ryuu-proxy-middleware',
configureServer: setupRyuuProxy,
},
],
envDir: './.environment',
envPrefix,
define: {
DOMO_APP_NAME: JSON.stringify(manifest.name),
DOMO_APP_VERSION: JSON.stringify(manifest.version),
},
css: {
preprocessorOptions: {
scss: {
api: 'modern',
},
},
},
test: {
globals: true,
environment: 'jsdom',
},
build: {
outDir: buildDir,
emptyOutDir: true,
sourcemap: false,
minify: true,
rollupOptions: {
output: {
sourcemap: false,
manualChunks: {
vendor: ['react', 'react-dom'],
redux: ['@reduxjs/toolkit', 'react-redux'],
},
},
},
},
clearScreen: false,
};
});