-
-
Notifications
You must be signed in to change notification settings - Fork 96
/
vite.config.ts
123 lines (106 loc) · 3.24 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/// <reference types="vitest" />
import react from '@vitejs/plugin-react';
import { existsSync, readFileSync } from 'fs';
import laravel from 'laravel-vite-plugin';
import { homedir } from 'os';
import { resolve } from 'path';
import { defineConfig, loadEnv } from 'vite';
export default defineConfig(({ mode, isSsrBuild }) => {
const env = loadEnv(mode, process.cwd(), '');
if (!env.VITE_BUILD_PATH) {
throw Error('VITE_BUILD_PATH not set');
}
if (!env.APP_URL) {
throw Error('APP_URL not set');
}
return {
// Required for SSR assets to load properly
base: '/assets/build',
// https://vitejs.dev/config/#build-options
build: {
outDir: isSsrBuild ? 'bootstrap/ssr' : `public/${env.VITE_BUILD_PATH}`,
assetsDir: '',
assetsInlineLimit: 4096,
},
// https://vitejs.dev/config/#plugins
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/tall-stack/app.ts', 'resources/js/app.tsx'],
ssr: 'resources/js/ssr.tsx',
refresh: ['resources/views/**'],
}),
react(),
],
ssr: {
noExternal: ['react-use'],
},
optimizeDeps: {
include: ['react-use'],
},
resolve: {
alias: {
'@': resolve(__dirname, './resources/js'),
livewire: resolve(__dirname, './vendor/livewire/livewire/dist/livewire.esm'),
},
},
test: {
environment: 'jsdom',
setupFiles: ['resources/js/setupTests.ts'],
include: ['resources/js/**/*.{test,spec}.{ts,tsx}'],
globals: true,
coverage: {
provider: 'v8',
reporter: ['text', 'html'],
include: [
/*
* Disregard coverage for Alpine.js stuff, mounting code, and /pages.
* - Alpine.js stuff will be removed.
* - Covering mounting code would just test the framework.
* - /pages should be covered by controller tests.
*/
'resources/js/common',
'resources/js/features',
'resources/js/utils',
],
exclude: [
'resources/js/common/components/+vendor', // shadcn/ui lib code
'**/index.ts',
'**/*.model.ts',
'**/*.test.ts',
'**/*.test.tsx',
'**/*.spec.ts',
'**/*.spec.tsx',
],
},
},
// @ see https://vitejs.dev/config/#server-options
server: detectServerConfig(env),
};
});
function detectServerConfig(env) {
const watch = {
// Explicitly ignore large volume directories to prevent running into system-level limits
// See https://vitejs.dev/config/server-options.html#server-watch
ignored: ['**/public/**', '**/storage/**', '**/vendor/**'],
};
const { host } = new URL(env.APP_URL);
const keyPath = resolve(homedir(), `.config/valet/Certificates/${host}.key`);
const certificatePath = resolve(homedir(), `.config/valet/Certificates/${host}.crt`);
if (!existsSync(keyPath) || !existsSync(certificatePath)) {
// NOTE do not set host, it defaults to either localhost or 0.0.0.0 for Docker
return {
port: env.VITE_PORT,
watch,
};
}
return {
hmr: { host },
host,
port: env.VITE_PORT,
watch,
https: {
key: readFileSync(keyPath),
cert: readFileSync(certificatePath),
},
};
}