deal/postbuild.js
2025-11-30 20:10:54 +03:00

39 lines
1.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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');