-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
123 lines (113 loc) · 3.28 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
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
import preact from '@preact/preset-vite'
import basicSsl from '@vitejs/plugin-basic-ssl'
import autoprefixer from 'autoprefixer'
import {visualizer} from 'rollup-plugin-visualizer'
import {defineConfig, loadEnv} from 'vite'
import checker from 'vite-plugin-checker'
import handlebars from 'vite-plugin-handlebars'
import {VitePWA} from 'vite-plugin-pwa'
import svgr from 'vite-plugin-svgr'
import manifest from './manifest.json'
const handlebarsPlugin = handlebars({
context: {
title: 'Prechat',
description:
'Prechat - a web messaging app built with Preact and TypeScript, similar to Telegram. ( Fast 3kB alternative to React with the same modern API )',
url: 'https://web-prechat.vercel.app',
},
})
const USE_HTTPS = false
const NO_MINIFY = false
const CHECK_CODE = false
// https://vitejs.dev/config/
// eslint-disable-next-line import/no-anonymous-default-export
export default ({mode}) => {
process.env = {...process.env, ...loadEnv(mode, process.cwd())}
return defineConfig({
plugins: [
svgr(),
preact(),
visualizer({
template: 'treemap',
gzipSize: true,
brotliSize: true,
filename: 'analyse.html',
}) as any, // eslint-disable-line
CHECK_CODE
? checker({
eslint: {
lintCommand: 'eslint --ext .tsx,.ts src',
},
})
: undefined,
handlebarsPlugin,
USE_HTTPS ? basicSsl() : undefined,
VitePWA({
manifest,
devOptions: {
enabled: true,
},
workbox: {
globPatterns: ['**/*.{js,ts,css,html}', '**/*.{svg,png,jpg,gif,woff2,json}'],
maximumFileSizeToCacheInBytes: 10 * 1024 * 1024,
},
}),
// chunkSplitPlugin({
// // customSplitting: {
// // 'ui-components': [/[\\/]src[\\/]components[\\/]ui[\\/]/]
// // }
// }),
].filter(Boolean),
build: {
target: 'es2020',
sourcemap: false,
minify: NO_MINIFY ? false : undefined,
},
css: {
postcss: {
plugins: [autoprefixer({add: true})],
},
modules: {
localsConvention: 'camelCase',
// generateScopedName: /* DEV ? */ '[name]__[local]___[hash:base64:5]',
// generateScopedName: '[local]__[hash:base64:10]',
generateScopedName: '[name]__[local]___[hash:base64:5]',
// hashPrefix: 'prefix',
},
preprocessorOptions: {
scss: {
additionalData: '@import "./src/css/mixins.scss";',
},
},
},
resolve: {
alias: {
/* For avoid conflicts with react-libraries */
react: 'preact/compat',
'react-dom': 'preact/compat',
/* common folders */
components: '/src/components',
hooks: '/src/hooks',
containers: '/src/containers',
modules: '/src/modules',
types: '/src/types',
lib: '/src/lib',
api: '/src/api',
state: '/src/state',
assets: '/src/assets',
common: '/src/common',
utilities: '/src/utilities',
context: '/src/context',
managers: '/src/managers',
storages: '/src/storages',
store: '/src/store',
// '@path':'/src/path'
},
},
server: {
port: 8000,
open: true,
https: USE_HTTPS,
},
})
}