vite.config.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. resolve: {
  13. alias: {
  14. '@vue/compiler-sfc': '@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js'
  15. }
  16. },
  17. optimizeDeps: {
  18. exclude: ['consolidate']
  19. }
  20. })
  21. function copyVuePlugin(): Plugin {
  22. return {
  23. name: 'copy-vue',
  24. generateBundle() {
  25. const filePath = path.resolve(
  26. __dirname,
  27. '../vue/dist/vue.runtime.esm-browser.js'
  28. )
  29. if (!fs.existsSync(filePath)) {
  30. throw new Error(
  31. `vue.runtime.esm-browser.js not built. ` +
  32. `Run "yarn build vue -f esm-browser" first.`
  33. )
  34. }
  35. this.emitFile({
  36. type: 'asset',
  37. fileName: 'vue.runtime.esm-browser.js',
  38. source: fs.readFileSync(filePath, 'utf-8')
  39. })
  40. }
  41. }
  42. }