-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
86 lines (83 loc) · 2.11 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
import path from 'path';
import fs from 'fs';
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import checker from 'vite-plugin-checker';
import tsconfigPaths from 'vite-tsconfig-paths';
import publicManifest from './public/manifest.json';
export const buildDir = 'build';
export const tmpDir = '.tmp';
export const envPrefix = 'DOMO_';
// https://vitejs.dev/config/
export default defineConfig(({ command }) => {
let manifest = publicManifest;
const tmpManifestPath = path.join(process.cwd(), tmpDir, 'manifest.json');
try {
manifest = JSON.parse(fs.readFileSync(tmpManifestPath).toString());
} catch (e) {}
return {
plugins: [
react(),
checker({
eslint: {
lintCommand: 'eslint',
useFlatConfig: true,
dev: {
logLevel: ['error'],
},
},
}),
tsconfigPaths(),
{
name: 'html-transform',
transformIndexHtml(html) {
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 (e) {
console.log('Could not replace "manifest.json" in build folder');
console.error(e);
}
},
},
],
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,
},
clearScreen: false,
};
});