deal/postbuild.js

39 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2025-11-30 18:10:54 +01:00
// postbuild.js
import { readFile, writeFile } from 'fs/promises';
import { join } from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const distPath = join(__dirname, 'dist');
const assetsPath = join(distPath, 'assets');
// Читаем index.html
const indexHtml = await readFile(join(distPath, 'index.html'), 'utf-8');
// Обновлённые регулярки — учитывают /deal/assets/ и атрибуты
const jsMatch = indexHtml.match(/<script[^>]+src="\/deal\/assets\/([^"]+\.js)"/);
const cssMatch = indexHtml.match(/<link[^>]+href="\/deal\/assets\/([^"]+\.css)"/);
if (!jsMatch || !cssMatch) {
console.error('❌ Не удалось найти JS/CSS в index.html');
console.log('Содержимое index.html:', indexHtml.substring(0, 500)); // Для отладки
process.exit(1);
}
const jsFile = jsMatch[1];
const cssFile = cssMatch[1];
const jsContent = `// Авто-сгенерировано: postbuild.js
import '/deal/assets/${jsFile}';`;
const cssContent = `/* Авто-сгенерировано: postbuild.js */
@import '/deal/assets/${cssFile}';`;
// Записываем прослойки
await writeFile(join(assetsPath, 'app.js'), jsContent);
await writeFile(join(assetsPath, 'app.css'), cssContent);
console.log('✅ Прослойки созданы: app.js и app.css');