-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
84 lines (82 loc) · 2.75 KB
/
vite.config.ts
File metadata and controls
84 lines (82 loc) · 2.75 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
import fs from 'node:fs';
import path from 'node:path';
import tailwindcss from '@tailwindcss/vite';
import basicSsl from '@vitejs/plugin-basic-ssl';
import react from '@vitejs/plugin-react';
import laravel from 'laravel-vite-plugin';
import { defineConfig, loadEnv } from 'vite';
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '');
const useReactCompiler =
env.VITE_REACT_COMPILER === undefined ||
env.VITE_REACT_COMPILER === 'true';
const appUrl = new URL(env.APP_URL || 'http://localhost');
const devServerHost = env.VITE_DEV_SERVER_HOST || appUrl.hostname;
const devServerPort = Number(env.VITE_DEV_SERVER_PORT || 5173);
const sslCertificatePath = path.resolve('ssl/cert.pem');
const sslKeyPath = path.resolve('ssl/key.pem');
const hasLocalSslCertificates =
fs.existsSync(sslCertificatePath) && fs.existsSync(sslKeyPath);
const useHttps =
env.VITE_DEV_SERVER_HTTPS !== undefined
? env.VITE_DEV_SERVER_HTTPS === 'true'
: hasLocalSslCertificates;
const devServerProtocol = useHttps ? 'https' : 'http';
const appOrigin = appUrl.origin;
const httpsConfig = useHttps
? hasLocalSslCertificates
? {
cert: fs.readFileSync(sslCertificatePath),
key: fs.readFileSync(sslKeyPath),
}
: {}
: undefined;
return {
resolve: {
alias: {
'@': path.resolve('resources/js'),
},
},
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.tsx'],
refresh: true,
}),
...(useHttps && !hasLocalSslCertificates ? [basicSsl()] : []),
react({
babel: useReactCompiler
? {
plugins: ['babel-plugin-react-compiler'],
}
: undefined,
}),
tailwindcss(),
],
server: {
host: '0.0.0.0',
port: devServerPort,
strictPort: true,
https: httpsConfig,
watch: {
ignored: [
'**/tmp/**',
'**/node_modules/**',
'**/vendor/**',
'**/storage/**',
],
},
cors: {
origin: [appOrigin],
},
origin: `${devServerProtocol}://${devServerHost}:${devServerPort}`,
hmr: {
host: devServerHost,
port: devServerPort,
protocol: useHttps ? 'wss' : 'ws',
},
},
esbuild: {
jsx: 'automatic',
},
};
});