-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
75 lines (68 loc) · 2.28 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
import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import chokidar from 'chokidar';
import path from 'path';
import fs from 'fs-extra';
// /** @type {import('vite').Plugin} */
// const viteServerConfig = {
// name: 'log-request-middleware',
// configureServer(server) {
// server.middlewares.use((req, res, next) => {
// res.setHeader('Access-Control-Allow-Origin', '*');
// res.setHeader('Access-Control-Allow-Methods', 'GET');
// res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
// res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
// next();
// });
// }
// };
export default defineConfig({
plugins: [
sveltekit(),
{
name: 'watch-routes-override',
configureServer() {
const project = process.env.PROJECT || 'upstream-overrides';
const projectPath = `src/.routes-${project}`;
const watcher = chokidar.watch(`src/${project}`, {
ignoreInitial: true,
ignored: ['node_modules', '**/.*'],
persistent: true
});
// Sync changes to .routes-${project}
watcher.on('add', (filePath) => {
const relativePath = path.relative(`src/${project}`, filePath);
const targetPath = path.join(projectPath, relativePath);
fs.ensureDirSync(path.dirname(targetPath));
fs.copyFileSync(filePath, targetPath);
console.log(`[File Added] Synced: ${relativePath}`);
});
watcher.on('change', (filePath) => {
const relativePath = path.relative(`src/${project}`, filePath);
const targetPath = path.join(projectPath, relativePath);
fs.copyFileSync(filePath, targetPath);
console.log(`[File Changed] Synced: ${relativePath}`);
});
watcher.on('unlink', (filePath) => {
const relativePath = path.relative(`src/${project}`, filePath);
const targetPath = path.join(projectPath, relativePath);
fs.removeSync(targetPath);
console.log(
`[File Deleted] Removed: ${relativePath}. To pick up changes from the default directory, restart the server.`
);
});
console.log(`Watching for changes in src/${project}...`);
}
}
],
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version),
APP_BUILD_HASH: JSON.stringify(process.env.APP_BUILD_HASH || 'dev-build')
},
build: {
sourcemap: true
},
worker: {
format: 'es'
}
});