-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
97 lines (92 loc) · 2.74 KB
/
vite.config.ts
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
// biome-ignore lint/correctness/noNodejsModules: build
import { existsSync } from 'node:fs'
// biome-ignore lint/correctness/noNodejsModules: build
import path, { resolve } from 'node:path'
import { config } from 'dotenv'
import { CSSOptions, LogLevel, LoggerOptions, createLogger, defineConfig } from 'vite'
import { PolyfillOptions, nodePolyfills } from 'vite-plugin-node-polyfills'
import sassDts from 'vite-plugin-sass-dts'
// Загружаем .env файл с выводом информации о статусе
const envPath = path.resolve(process.cwd(), '.env')
if (existsSync(envPath)) {
console.log('[vite.config] Loading .env file from:', envPath)
config({ path: envPath })
} else {
console.warn('[vite.config] No .env file found')
}
export const isDev = process.env.NODE_ENV !== 'production' && !process.env.CI
console.log(`[vite.config] ${isDev ? 'dev' : 'prod'} mode`)
const polyfillOptions = {
include: ['path', 'stream', 'util'],
exclude: ['http'],
globals: { Buffer: true },
overrides: { fs: 'memfs' },
protocolImports: true
} as PolyfillOptions
// Базовая конфигурация логгера
const customLogger = createLogger(
'info' as LogLevel,
{
warn: (message: string, options: LoggerOptions) => {
// Игнорируем определенные предупреждения
if (
message.includes('legacy JS API') ||
message.includes('mixed-decls') ||
message.startsWith('Future global-builtin')
) {
return
}
console.warn(message, options)
}
} as LoggerOptions
)
export default defineConfig({
resolve: {
alias: {
'~': resolve('./src'),
'@': resolve('./public'),
'/icons': resolve('./public/icons'),
'/fonts': resolve('./public/fonts')
}
},
envPrefix: 'PUBLIC_',
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
quietDeps: true,
silenceDeprecations: ['mixed-decls', 'legacy-js-api'],
additionalData: (content: string) => `@use '~/styles/global' as *;\n${content}`,
includePaths: ['./public', './src/styles', './node_modules']
}
} as CSSOptions['preprocessorOptions']
},
customLogger,
plugins: [nodePolyfills(polyfillOptions), sassDts()],
build: {
target: 'esnext',
sourcemap: isDev,
minify: 'terser',
chunkSizeWarningLimit: 777,
terserOptions: {
compress: {
drop_console: !isDev
}
},
rollupOptions: {
output: {
sourcemapExcludeSources: true
}
}
},
ssr: {
noExternal: ['@urql/core', '@urql/exchange-graphcache'],
target: 'node',
optimizeDeps: {
include: ['@urql/core', '@urql/exchange-graphcache']
}
},
optimizeDeps: {
include: ['buffer']
}
})