-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
83 lines (75 loc) · 1.95 KB
/
vite.config.js
File metadata and controls
83 lines (75 loc) · 1.95 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
import { defineConfig } from 'vite';
import { exec } from 'child_process';
const autoBuildPlugin = () => {
let isBuilding = false;
return {
name: 'auto-build',
handleHotUpdate(ctx) {
if (ctx.file.includes('/src/') && !isBuilding) {
isBuilding = true;
console.log('Source file changed:', ctx.file.split('/').pop(), '- rebuilding...');
exec('npm run build', (error, stdout, stderr) => {
isBuilding = false;
if (error) {
console.error('Build error:', error);
return;
}
if (stderr) {
console.error('Build stderr:', stderr);
return;
}
console.log('✅ Build completed successfully');
ctx.server.ws.send({
type: 'full-reload'
});
});
}
if (ctx.file.includes('/src/')) {
return [];
}
}
};
};
export default defineConfig({
root: '.', // Serve from project root instead of examples/basic
publicDir: 'public',
plugins: [autoBuildPlugin()],
server: {
port: 5173,
open: 'examples/basic/', // Open the basic example by default
cors: true,
watch: {
include: ['src/**/*', 'dist/**/*', 'examples/**/*'],
ignored: ['**/node_modules/**', '**/.git/**']
},
hmr: {
overlay: false
}
},
resolve: {
alias: {
'/models': '/models',
'belowjs': '/dist/belowjs.js'
}
},
build: {
outDir: 'dist',
cssCodeSplit: false, // Bundle all CSS into one file
lib: {
entry: 'src/index.js',
formats: ['es'], // Only build ES modules
fileName: () => 'belowjs.js'
},
rollupOptions: {
external: ['three'],
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name && assetInfo.name.endsWith('.css')) {
return 'belowjs.css';
}
return '[name].[ext]';
}
}
}
}
});