templates/vite-templates/vite.config.js
2026-04-12 21:03:18 +03:00

144 lines
3.7 KiB
JavaScript
Raw 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.

import { defineConfig } from 'vite';
import vituum from 'vituum';
import pug from '@vituum/vite-plugin-pug';
import twig from '@vituum/vite-plugin-twig';
import { resolve } from 'path';
import basicSsl from '@vitejs/plugin-basic-ssl';
process.on('unhandledRejection', (reason, promise) => {
console.warn('⚠️ Unhandled Promise Rejection:', reason);
// Не останавливать процесс - просто логировать
});
export default defineConfig({
plugins: [
vituum({
pages: {
dir: './src/twig/pages', // Указываем правильный путь к Twig страницам
formats: ['twig']
},
// Настройки для стабильной работы
options: {
reload: true,
verbose: true
}
}),
// Twig конфигурация
twig({
root: './src/twig',
namespaces: {
layouts: './src/twig/layouts',
components: './src/twig/components',
data: './src/data'
},
// Более мягкие настройки для разработки
options: {
autoescape: false,
strict_vars: false
}
}),
// Pug для других страниц (если нужно)
pug({
root: './src',
options: {
pretty: true,
basedir: './src'
}
}),
basicSsl()
],
server: {
host: true,
port: 3000,
https: true,
open: true,
// Настройки для стабильной работы HMR
hmr: {
overlay: true
},
// Не останавливать сервер при ошибках
middlewareMode: false
},
// Настройки сборки
build: {
outDir: 'dist',
assetsDir: 'assets',
sourcemap: false, // Отключаем sourcemaps для чистоты
rollupOptions: {
output: {
// Группируем CSS в один файл
assetFileNames: (assetInfo) => {
const info = assetInfo.name.split('.');
const ext = info[info.length - 1];
if (ext === 'css') {
return 'assets/css/style-[hash].css'; // Один CSS файл
}
if (/\.(png|jpe?g|svg|gif|tiff|bmp|ico)$/i.test(assetInfo.name)) {
return 'assets/images/[name]-[hash][extname]';
}
if (/\.(woff2?|eot|ttf|otf)$/i.test(assetInfo.name)) {
return 'assets/fonts/[name]-[hash][extname]';
}
return 'assets/[name]-[hash][extname]';
},
// Группируем JS
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js'
}
},
// Минификация
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true
}
}
},
// Минимальная обработка ошибок
esbuild: {
// Продолжать работу при ошибках
logOverride: { 'this-is-undefined-in-esm': 'silent' }
},
// Обработка ошибок
optimizeDeps: {
force: true
},
css: {
preprocessorOptions: {
scss: {
silenceDeprecations: ['legacy-js-api']
// additionalData: `
// @import "./src/styles/_vars.scss";
// @import "./src/styles/_scss";
// `
}
}
},
resolve: {
alias: {
'@': resolve(process.cwd(), 'src'),
'@twig': resolve(process.cwd(), 'src/twig'),
'@styles': resolve(process.cwd(), 'src/styles'),
'@js': resolve(process.cwd(), 'src/js'),
'@images': resolve(process.cwd(), 'src/images'),
'@data': resolve(process.cwd(), 'src/data')
}
}
});