Remove legacy configuration files and scripts, transitioning to Vite for build and development processes. Introduce new HTML files for the landing and terms pages, along with stubs for API responses. Update package.json and package-lock.json to include Vite and related dependencies, enhancing the project structure and build efficiency.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import react from '@vitejs/plugin-react';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
// Express middleware для stubs
|
||||
const stubsMiddleware = () => ({
|
||||
name: 'stubs-middleware',
|
||||
configureServer(server: any) {
|
||||
const stubsPath = path.resolve(__dirname, 'stubs/api');
|
||||
|
||||
server.middlewares.use('/api', (req: any, res: any, next: any) => {
|
||||
// Получаем путь запроса без /api
|
||||
const apiPath = req.url.replace(/\?.*$/, ''); // убираем query params
|
||||
const stubFile = path.join(stubsPath, `${apiPath}.js`);
|
||||
|
||||
// Проверяем существует ли stub файл
|
||||
if (fs.existsSync(stubFile)) {
|
||||
try {
|
||||
// Очищаем кеш модуля для hot reload
|
||||
delete require.cache[require.resolve(stubFile)];
|
||||
const stub = require(stubFile);
|
||||
|
||||
// Если это функция, вызываем её
|
||||
if (typeof stub === 'function') {
|
||||
stub(req, res, next);
|
||||
} else if (stub.default && typeof stub.default === 'function') {
|
||||
stub.default(req, res, next);
|
||||
} else {
|
||||
// Если это просто объект, отдаём как JSON
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(stub.default || stub));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error loading stub ${stubFile}:`, error);
|
||||
res.statusCode = 500;
|
||||
res.end(JSON.stringify({ error: 'Internal Server Error' }));
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const isProd = mode === 'production';
|
||||
|
||||
return {
|
||||
plugins: [
|
||||
react(),
|
||||
stubsMiddleware()
|
||||
],
|
||||
base: isProd ? 'https://static.brojs.ru/landing/main/' : '/',
|
||||
server: {
|
||||
port: 8099,
|
||||
open: '/',
|
||||
},
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
assetsDir: '.', // Все ассеты в корень dist
|
||||
rollupOptions: {
|
||||
input: {
|
||||
main: path.resolve(__dirname, 'index.html'),
|
||||
terms: path.resolve(__dirname, 'terms.html'),
|
||||
},
|
||||
output: {
|
||||
entryFileNames: '[name].[hash].js',
|
||||
chunkFileNames: '[name].[hash].js',
|
||||
assetFileNames: '[name].[hash].[ext]'
|
||||
}
|
||||
},
|
||||
},
|
||||
css: {
|
||||
modules: {
|
||||
localsConvention: 'camelCase',
|
||||
},
|
||||
},
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': path.resolve(__dirname, './src'),
|
||||
},
|
||||
},
|
||||
}}); // Двойная скобка для закрытия return и defineConfig
|
||||
|
||||
Reference in New Issue
Block a user