/
vite.config.ts
41 lines (38 loc) 路 1013 Bytes
/
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
import fs from 'fs'
import path from 'path'
import { defineConfig, Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import execa from 'execa'
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
export default defineConfig({
plugins: [vue(), copyVuePlugin()],
define: {
__COMMIT__: JSON.stringify(commit),
__VUE_PROD_DEVTOOLS__: JSON.stringify(true)
},
optimizeDeps: {
exclude: ['@vue/repl']
}
})
function copyVuePlugin(): Plugin {
return {
name: 'copy-vue',
generateBundle() {
const filePath = path.resolve(
__dirname,
'../vue/dist/vue.runtime.esm-browser.js'
)
if (!fs.existsSync(filePath)) {
throw new Error(
`vue.runtime.esm-browser.js not built. ` +
`Run "yarn build vue -f esm-browser" first.`
)
}
this.emitFile({
type: 'asset',
fileName: 'vue.runtime.esm-browser.js',
source: fs.readFileSync(filePath, 'utf-8')
})
}
}
}