-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.mts
63 lines (55 loc) · 1.81 KB
/
vite.config.mts
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
/* eslint-disable @typescript-eslint/naming-convention */
import { execSync } from 'node:child_process'
import tailwindcss from '@tailwindcss/vite'
import browserslistToEsbuild from 'browserslist-to-esbuild'
import { defineConfig } from 'vite'
import { createHtmlPlugin } from 'vite-plugin-html'
// import type { AcceptedPlugin } from 'tailwindcss/node_modules/postcss'
// import type { AcceptedPlugin } from 'postcss'
// import type { AcceptedPlugin } from 'tailwindcss/stubs/postcss.config'
import type { UserConfig } from 'vite'
const filesPathToExclude: (string | RegExp)[] = [/[-_]buildignore/]
// Function to get the current commit hash
function getCurrentCommitHash(): string {
try {
return execSync('git log -1 --format="%H"').toString().trim()
} catch (error) {
console.warn('Failed to get Git commit hash:', error)
return 'gitCommitHashUnknown'
}
}
export default defineConfig(({ command, mode }) => {
console.log('VITE COMMAND:', command)
console.log('VITE MODE:', mode)
console.log('NODE MODE:', process.env.NODE_ENV)
let title = 'Expt-Template Mode Unknown'
if (mode === 'development') {
title = 'Expt-Template Development'
} else if (mode === 'production') {
title = 'Expt-Template Production'
}
const config = {
build: {
target: browserslistToEsbuild(),
manifest: true,
rollupOptions: {
external: filesPathToExclude,
},
// outDir: '../dist', // Output to the project root's dist folder
},
plugins: [
tailwindcss(),
createHtmlPlugin({
minify: true,
}),
],
css: {
postcss: './postcss.config.cjs',
},
define: {
'import.meta.env.VITE_APP_TITLE': JSON.stringify(title),
'__COMMIT_HASH__': JSON.stringify(getCurrentCommitHash()),
},
} satisfies UserConfig
return config
})