-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvite.config.ts
More file actions
154 lines (146 loc) · 5.07 KB
/
vite.config.ts
File metadata and controls
154 lines (146 loc) · 5.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { resolve } from 'node:path'
import { CSSOptions, defineConfig, LightningCSSOptions } from 'vite'
import { nodePolyfills, PolyfillOptions } from 'vite-plugin-node-polyfills'
const isDev = process.env.NODE_ENV !== 'production' && !process.env.CI
const isDebug = process.env.DEBUG_BUILD === 'true' // Для отладки prod сборки
const polyfillOptions = {
include: ['path', 'stream', 'util', 'buffer'],
exclude: ['http'],
globals: { Buffer: true },
overrides: { fs: 'memfs' },
protocolImports: true
} as PolyfillOptions
export default defineConfig({
server: {
hmr: isDev
? {
timeout: 120000, // Увеличиваем HMR таймаут
overlay: true // Показываем overlay с ошибками только в dev
}
: false, // Отключаем HMR в production
watch: isDev
? {
// Следим за изменениями в SCSS файлах явно
usePolling: false,
interval: 100
}
: undefined
},
resolve: {
alias: {
'~': resolve('./src'),
'@': resolve('./public')
}
},
envPrefix: 'PUBLIC_',
css: {
// Включаем Lightning CSS transformer после исправления ::global
transformer: 'lightningcss',
lightningcss: {
// Целевые браузеры для максимальной совместимости
targets: {
chrome: 95,
firefox: 90,
safari: 14,
edge: 95
},
// Включаем только поддерживаемые draft CSS features
drafts: {
customMedia: true
},
cssModules: {
// В dev/debug режиме упрощаем имена классов для лучшего HMR и отладки
generateScopedName: isDev || isDebug ? '[name]__[local]' : '[name]__[local]___[hash:base64:5]'
}
} as LightningCSSOptions,
modules: {
// В dev/debug режиме упрощаем имена классов для лучшего HMR и отладки
generateScopedName: isDev || isDebug ? '[name]__[local]' : '[name]__[local]___[hash:base64:5]'
},
devSourcemap: isDev, // Source maps для стилей в dev режиме
preprocessorOptions: {
scss: {
// Используем modern-compiler API везде для избежания deprecation warnings
api: 'modern-compiler',
quietDeps: true,
silenceDeprecations: ['mixed-decls', 'legacy-js-api', 'import', 'global-builtin', 'color-4-api'],
logger: {
warn: () => {} // Полностью отключаем warnings от Sass
},
additionalData: (content: string) => `@use '~/styles/global' as *;\n${content}`,
includePaths: ['./public', './src/styles', './node_modules']
}
} as CSSOptions['preprocessorOptions']
},
plugins: [nodePolyfills(polyfillOptions)],
publicDir: 'public',
// Расширяем список разрешенных типов файлов
assetsInclude: [
'**/*.svg',
'**/*.png',
'**/*.jpg',
'**/*.jpeg',
'**/*.gif',
'**/*.woff',
'**/*.woff2',
'**/icons/**/*',
'**/public/**/*'
],
build: {
target: 'esnext',
sourcemap: isDev || isDebug, // Source maps в dev и debug режимах
minify: isDev || isDebug ? false : 'terser', // Минификация только в production (не в debug)
cssMinify: isDebug ? false : 'lightningcss', // CSS минификация отключена в debug режиме
chunkSizeWarningLimit: 777,
terserOptions: {
compress: {
drop_console: !isDev // Удаляем console.log в production
}
},
// Отключение предупреждений о неразрешенных статических ресурсах
assetsInlineLimit: 0,
rollupOptions: {
external: ['bufferutil', 'utf-8-validate'],
output: {
// Копирование статических файлов без предупреждений
assetFileNames: (assetInfo) => {
// Сохраняем оригинальную структуру путей
return assetInfo.name || ''
},
sourcemapExcludeSources: true,
manualChunks: (id) => {
if (id.includes('node_modules')) {
if (id.includes('swiper')) {
return 'swiper'
}
if (id.includes('typograf')) {
return 'typograf'
}
if (id.includes('i18next')) {
return 'i18next'
}
if (id.includes('graphql')) {
return 'graphql'
}
if (id.includes('@solidjs/start')) {
return 'solid-start'
}
if (id.includes('solid')) {
return 'solid'
}
}
}
}
}
},
ssr: {
noExternal: ['@urql/core', '@solidjs/meta', '@solidjs/router'],
target: 'node',
optimizeDeps: {
include: ['@urql/core']
}
},
optimizeDeps: {
include: ['@urql/core', 'buffer']
}
})