vite.config.ts 1011 B

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