vite.config.ts 964 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import fs from 'fs'
  2. import path from 'path'
  3. import { defineConfig, Plugin } from 'vite'
  4. import vue from '@vitejs/plugin-vue'
  5. import execa from 'execa'
  6. const commit = execa.sync('git', ['rev-parse', 'HEAD']).stdout.slice(0, 7)
  7. export default defineConfig({
  8. plugins: [vue(), copyVuePlugin()],
  9. define: {
  10. __COMMIT__: JSON.stringify(commit)
  11. },
  12. optimizeDeps: {
  13. exclude: ['@vue/repl']
  14. }
  15. })
  16. function copyVuePlugin(): Plugin {
  17. return {
  18. name: 'copy-vue',
  19. generateBundle() {
  20. const filePath = path.resolve(
  21. __dirname,
  22. '../vue/dist/vue.runtime.esm-browser.js'
  23. )
  24. if (!fs.existsSync(filePath)) {
  25. throw new Error(
  26. `vue.runtime.esm-browser.js not built. ` +
  27. `Run "yarn build vue -f esm-browser" first.`
  28. )
  29. }
  30. this.emitFile({
  31. type: 'asset',
  32. fileName: 'vue.runtime.esm-browser.js',
  33. source: fs.readFileSync(filePath, 'utf-8')
  34. })
  35. }
  36. }
  37. }