supertonic 3

This commit is contained in:
haeon
2026-05-06 23:09:06 +02:00
parent 6fc89ea89e
commit 0a98c9f127
47 changed files with 530 additions and 411 deletions

View File

@@ -1,6 +1,38 @@
import { createReadStream, existsSync, statSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootAssetsDir = path.resolve(__dirname, '../assets');
function serveRootAssets() {
return {
name: 'serve-root-assets',
configureServer(server) {
server.middlewares.use('/assets', (req, res, next) => {
const urlPath = decodeURIComponent((req.url || '').split('?')[0]);
const filePath = path.resolve(rootAssetsDir, `.${urlPath}`);
if (!filePath.startsWith(rootAssetsDir) || !existsSync(filePath)) {
next();
return;
}
const stat = statSync(filePath);
if (!stat.isFile()) {
next();
return;
}
createReadStream(filePath).pipe(res);
});
}
};
}
export default defineConfig({
plugins: [serveRootAssets()],
server: {
port: 3000,
open: true