2021-03-28 13:35:45 +08:00
|
|
|
import fs from 'fs'
|
|
|
|
import path from 'path'
|
|
|
|
import { defineConfig, Plugin } from 'vite'
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
2021-03-29 14:07:04 +08:00
|
|
|
import execa from 'execa'
|
|
|
|
|
|
|
|
const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
|
2021-03-28 13:35:45 +08:00
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
plugins: [vue(), copyVuePlugin()],
|
2021-03-29 14:07:04 +08:00
|
|
|
define: {
|
|
|
|
__COMMIT__: JSON.stringify(commit)
|
|
|
|
},
|
2021-03-31 07:51:55 +08:00
|
|
|
resolve: {
|
|
|
|
alias: {
|
|
|
|
'@vue/compiler-sfc': '@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js'
|
|
|
|
}
|
|
|
|
},
|
2021-03-28 13:35:45 +08:00
|
|
|
optimizeDeps: {
|
|
|
|
exclude: ['consolidate']
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
function copyVuePlugin(): Plugin {
|
|
|
|
return {
|
|
|
|
name: 'copy-vue',
|
2021-03-29 14:07:04 +08:00
|
|
|
generateBundle() {
|
2021-03-28 13:35:45 +08:00
|
|
|
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')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|