supertonic 3
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user