-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
28 lines (26 loc) · 760 Bytes
/
Copy pathvite.config.ts
File metadata and controls
28 lines (26 loc) · 760 Bytes
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
import { defineConfig } from 'vite';
import path from 'path';
import fs from 'fs';
export default defineConfig(({ mode }) => ({
root: 'src',
build: {
outDir: '..',
},
base: mode === 'development' ? '' : '/pahjs/',
plugins: [
{
name: 'serve-tiles-directory',
configureServer(server) {
const tilesPath = path.resolve(__dirname, 'tiles');
server.middlewares.use('/pahjs/tiles', (req, res, next) => {
const filePath = path.join(tilesPath, req.url!);
const stream = fs.createReadStream(filePath);
stream.on('error', () => next());
res.statusCode = 200;
res.setHeader('Content-Type', 'image/svg+xml');
stream.pipe(res);
});
},
},
],
}));