-
-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathvite.config.ts
More file actions
90 lines (84 loc) · 2.94 KB
/
vite.config.ts
File metadata and controls
90 lines (84 loc) · 2.94 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
import { wayfinder } from '@laravel/vite-plugin-wayfinder';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react';
import fs from 'fs';
import { resolve } from 'path';
import { defineConfig, type Plugin } from 'vite';
function copyStaticAssets(): Plugin {
return {
name: 'copy-static-assets',
closeBundle() {
fs.copyFileSync(
resolve(__dirname, 'resources/images/favicon.svg'),
resolve(__dirname, 'dist/favicon.svg'),
);
},
};
}
const hotFiles = [
resolve(__dirname, 'public/hot-translations'),
resolve(__dirname, 'vendor/orchestra/testbench-core/laravel/public/hot-translations'),
];
export default defineConfig({
plugins: [
react(),
tailwindcss(),
wayfinder({
command: 'php vendor/bin/testbench wayfinder:generate',
path: 'resources/js',
formVariants: true,
patterns: ['routes/**/*.php', 'src/**/Http/**/*.php'],
}),
{
name: 'translations-hot-file',
configureServer(server) {
const clean = () => hotFiles.forEach((f) => fs.existsSync(f) && fs.unlinkSync(f));
server.httpServer?.once('listening', () => {
const addr = server.httpServer?.address();
const port = typeof addr === 'object' && addr ? addr.port : 5173;
const url = `http://localhost:${port}`;
for (const hotFile of hotFiles) {
fs.mkdirSync(resolve(hotFile, '..'), { recursive: true });
fs.writeFileSync(hotFile, url);
}
});
process.on('exit', clean);
process.on('SIGINT', () => process.exit());
process.on('SIGTERM', () => process.exit());
},
},
copyStaticAssets(),
],
server: {
cors: true,
},
build: {
outDir: 'dist',
emptyOutDir: true,
manifest: true,
rollupOptions: {
input: {
app: resolve(__dirname, 'resources/js/app.tsx'),
},
output: {
entryFileNames: 'js/app.js',
chunkFileNames: 'js/[name]-[hash].js',
assetFileNames: (assetInfo) => {
if (assetInfo.name?.endsWith('.css')) {
return 'css/app.css';
}
return 'assets/[name]-[hash][extname]';
},
},
},
},
resolve: {
dedupe: ['react', 'react-dom', '@inertiajs/react'],
alias: {
'@': resolve(__dirname, 'resources/js'),
'@inertiajs/react': resolve(__dirname, 'node_modules/@inertiajs/react'),
'react': resolve(__dirname, 'node_modules/react'),
'react-dom': resolve(__dirname, 'node_modules/react-dom'),
},
},
});