-
Notifications
You must be signed in to change notification settings - Fork 248
/
vite.config.js
117 lines (105 loc) · 2.58 KB
/
vite.config.js
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
import { defineConfig, loadEnv } from 'vite'
import { qrcode } from 'vite-plugin-qrcode'
import { visualizer } from 'rollup-plugin-visualizer'
import fs from 'fs'
import gitprocess from 'child_process'
import monacoEditorPlugin from 'vite-plugin-monaco-editor'
import path from 'path'
import svgLoader from 'vite-svg-loader'
import vue from '@vitejs/plugin-vue2'
import crypto from 'crypto'
let date
if (typeof gitprocess === 'function') {
date = new Date(
gitprocess
.execSync('git log -1 --date=format:"%Y/%m/%d %T" --format="%ad"')
.toString()
)
} else {
date = new Date()
}
process.env.VITE_APP_VERSION = require('./package.json').version
process.env.VITE_APP_BUILD_DATE =
date.getDate() +
' ' +
date.toLocaleString('en-US', { month: 'short' }).toLowerCase()
function makeExchangeList() {
const exchanges = []
fs.readdirSync('./src/worker/exchanges/').forEach(file => {
if (/\w+\.ts$/.test(file) && file !== 'index.ts') {
exchanges.push(file.replace(/\.ts$/, ''))
}
})
return exchanges.join(',')
}
process.env.VITE_APP_EXCHANGES = makeExchangeList()
export default defineConfig(({ mode }) => {
const env = {
...process.env,
...loadEnv(mode, process.cwd(), '')
}
const processEnvValues = {
'process.env': Object.entries(env).reduce((prev, [key, val]) => {
return {
...prev,
[key]: val
}
}, {})
}
const hash = crypto
.createHash('md5')
.update('aggr')
.digest('hex')
.substring(0, 7)
return {
define: {
...processEnvValues
},
base: mode === 'github' ? env.VITE_APP_BASE_PATH : '/',
plugins: [
vue(),
svgLoader({
defaultImport: 'url' // 👈
}),
visualizer(),
monacoEditorPlugin.default({}),
qrcode() // only applies in dev mode
// Add the terser plugin for production builds to remove console.log
],
build: {
minify: 'terser',
rollupOptions: {
output: {
entryFileNames: `[name].` + hash + `.js`,
chunkFileNames: `[name].` + hash + `.js`,
assetFileNames: `[name].` + hash + `.[ext]`
}
},
terserOptions: {
compress: {
drop_console: true
}
}
},
server: {
port: 8080,
host: '0.0.0.0'
},
resolve: {
alias: [
{
find: '@',
replacement: path.resolve(__dirname, 'src')
}
]
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {
additionalData: `@import "@/assets/sass/variables.scss";`
}
}
}
}
})