-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
144 lines (139 loc) · 4.64 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { ValidateEnv as validateEnv } from '@julr/vite-plugin-validate-env';
import basicSsl from '@vitejs/plugin-basic-ssl';
import reactSwc from '@vitejs/plugin-react-swc';
import { execSync } from 'child_process';
import { visualizer } from 'rollup-plugin-visualizer';
import {
defineConfig,
type HtmlTagDescriptor,
loadEnv,
type UserConfig,
} from 'vite';
import checker from 'vite-plugin-checker';
import { compression } from 'vite-plugin-compression2';
import { VitePWA } from 'vite-plugin-pwa';
import svgr from 'vite-plugin-svgr';
import webfontDownload from 'vite-plugin-webfont-dl';
import tsconfigPaths from 'vite-tsconfig-paths';
import envConfig from './env';
/* Get commit hash */
const commitHash = execSync('git rev-parse --short HEAD').toString();
function umamiPlugin(options: { id: string | undefined, src: string | undefined }) {
return {
name: 'html-transform',
transformIndexHtml: () => {
if (!options.id || !options.src) {
console.warn('Umami src and id not set.');
return [];
}
const tags: HtmlTagDescriptor[] = [
{
tag: 'script',
attrs: {
async: true,
defer: true,
'data-website-id': options.id,
src: options.src,
},
},
];
return tags;
},
};
}
export default defineConfig(({ mode }) => {
const isProd = mode === 'production';
console.log('Mode:', mode);
const env = loadEnv(mode, process.cwd(), '');
const config: UserConfig = {
define: {
'import.meta.env.APP_COMMIT_HASH': JSON.stringify(commitHash),
'import.meta.env.APP_VERSION': JSON.stringify(env.npm_package_version),
},
plugins: [
!isProd ? basicSsl() : undefined,
isProd ? checker({
// typescript: true,
eslint: {
lintCommand: 'eslint ./src',
},
stylelint: {
lintCommand: 'stylelint "./src/**/*.css"',
},
}) : undefined,
isProd ? umamiPlugin({
id: env.APP_UMAMI_ID,
src: env.APP_UMAMI_SRC,
}) : undefined,
VitePWA({
// buildBase: './build/',
strategies: 'generateSW',
registerType: 'prompt',
injectRegister: 'script',
devOptions: { enabled: false },
includeAssets: ['app-icon.svg'],
manifest: {
name: 'Timur',
short_name: 'Timur',
description: 'Timur - Phase Zero',
theme_color: '#fafaf0',
},
workbox: {
globPatterns: ['**/*.{js,css,html,png,svg,ico}'],
},
pwaAssets: {
config: true,
overrideManifestIcons: true,
},
}),
svgr(),
reactSwc(),
tsconfigPaths(),
webfontDownload(),
validateEnv(envConfig),
isProd ? compression() : undefined,
isProd ? visualizer({ sourcemap: true }) : undefined,
],
css: {
devSourcemap: isProd,
modules: {
scopeBehaviour: 'local',
localsConvention: 'camelCaseOnly',
},
},
envPrefix: 'APP_',
server: {
port: 3000,
host: 'local.timur.dev.togglecorp.com',
strictPort: true,
},
build: {
outDir: './build',
sourcemap: isProd,
emptyOutDir: true,
rollupOptions: {
output: {
chunkFileNames: 'chunk-[name].[hash].js',
entryFileNames: 'entry-[name].[hash].js',
assetFileNames: 'asset-[name]-[hash].[ext]',
manualChunks: {
'code-mirror': [
'@codemirror/lang-markdown',
'@uiw/codemirror-theme-github',
'@uiw/react-codemirror',
],
'codemirror-vim-mode': ['@replit/codemirror-vim'],
},
},
},
},
test: {
environment: 'happy-dom',
coverage: {
enabled: true,
reporter: 'html',
},
},
};
return config;
});