-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
71 lines (63 loc) · 1.67 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
// https://www.youtube.com/watch?v=u-nQzshfZcc
// https://vitejs.dev/guide/backend-integration
import { defineConfig, Plugin, ServerOptions, BuildOptions } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import dns from 'dns';
import svgr from 'vite-plugin-svgr';
import tsconfigPaths from 'vite-tsconfig-paths';
import { TanStackRouterVite } from '@tanstack/router-vite-plugin'
// https://vitejs.dev/config/server-options.html#server-host
dns.setDefaultResultOrder('verbatim');
const APP_NAME = 'webkit';
const OUT_DIR = 'dist';
const PORT = 5888;
const ROOT = path.resolve('./');
const BASE = __dirname.replace(ROOT, '');
// Plugins
const plugins: Plugin[] = [
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
react(),
svgr({
}),
tsconfigPaths(),
{
name: 'php',
handleHotUpdate({ file, server }) {
const endsWith = file.endsWith('.php') || file.endsWith('.html');
if (file.includes(`${APP_NAME}/`) && endsWith) {
console.log('[PHP/HTML File Updated]: ', file);
server.ws.send({ type: 'full-reload' });
}
}
},
TanStackRouterVite(),
];
// Server
const server: ServerOptions = {
port: PORT,
strictPort: true,
};
// Build
const build: BuildOptions = {
manifest: true,
assetsDir: '.',
outDir: OUT_DIR,
emptyOutDir: true,
sourcemap: true,
rollupOptions: {
input: ['src/main.tsx'],
output: {
entryFileNames: 'app.js',
assetFileNames: '[name].[ext]',
}
}
};
// https://vitejs.dev/config/
export default defineConfig({
base: process.env.NODE_ENV === 'production' ? `${BASE}/${OUT_DIR}/` : BASE,
plugins,
server,
build,
});