Skip to content

Commit 37c5fd6

Browse files
Fix: Include data directory in build output
Added Vite plugin to copy data directory to dist folder during build. This ensures scraped data files are available on the deployed site. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 6446875 commit 37c5fd6

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

vite.config.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,44 @@
11
import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
3+
import { copyFileSync, mkdirSync, readdirSync, statSync } from 'fs';
4+
import { join } from 'path';
5+
6+
// Plugin to copy data directory to dist
7+
function copyDataPlugin() {
8+
return {
9+
name: 'copy-data',
10+
closeBundle() {
11+
const dataDir = 'data';
12+
const distDataDir = 'dist/data';
13+
14+
function copyDir(src, dest) {
15+
mkdirSync(dest, { recursive: true });
16+
const entries = readdirSync(src);
17+
18+
for (const entry of entries) {
19+
const srcPath = join(src, entry);
20+
const destPath = join(dest, entry);
21+
22+
if (statSync(srcPath).isDirectory()) {
23+
copyDir(srcPath, destPath);
24+
} else {
25+
copyFileSync(srcPath, destPath);
26+
}
27+
}
28+
}
29+
30+
try {
31+
copyDir(dataDir, distDataDir);
32+
console.log('✓ Copied data directory to dist');
33+
} catch (err) {
34+
console.warn('⚠ Could not copy data directory:', err.message);
35+
}
36+
}
37+
};
38+
}
339

440
export default defineConfig({
5-
plugins: [react()],
41+
plugins: [react(), copyDataPlugin()],
642
base: '/usedevpricetracker/',
743
build: {
844
outDir: 'dist',

0 commit comments

Comments
 (0)