63 lines
1.4 KiB
TypeScript
63 lines
1.4 KiB
TypeScript
/// <reference types="vitest/config" />
|
|
import path from 'path';
|
|
import type { Plugin } from 'vite';
|
|
import { defineConfig } from 'vite';
|
|
import react from '@vitejs/plugin-react';
|
|
|
|
const buttonRoutePlugin = (): Plugin => ({
|
|
name: 'button-route',
|
|
configureServer(server) {
|
|
server.middlewares.use((req, res, next) => {
|
|
const url = req.url ?? '';
|
|
const [pathname, search = ''] = url.split('?');
|
|
const query = search ? `?${search}` : '';
|
|
|
|
if (pathname === '/button') {
|
|
res.statusCode = 301;
|
|
res.setHeader('Location', `/button/${query}`);
|
|
res.end();
|
|
return;
|
|
}
|
|
|
|
if (pathname === '/button/' || pathname === '/button/index.html') {
|
|
req.url = `/button/index.html${query}`;
|
|
}
|
|
|
|
next();
|
|
});
|
|
},
|
|
});
|
|
|
|
export default defineConfig({
|
|
plugins: [react(), buttonRoutePlugin()],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, '.'),
|
|
},
|
|
},
|
|
build: {
|
|
rollupOptions: {
|
|
input: {
|
|
main: path.resolve(__dirname, 'index.html'),
|
|
button: path.resolve(__dirname, 'button/index.html'),
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
port: 3001,
|
|
host: '0.0.0.0',
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://127.0.0.1:8000',
|
|
changeOrigin: true,
|
|
},
|
|
},
|
|
},
|
|
test: {
|
|
globals: true,
|
|
environment: 'jsdom',
|
|
setupFiles: './tests/setup.ts',
|
|
exclude: ['node_modules/**', 'dist/**', '.opencode/**'],
|
|
},
|
|
});
|