vite.config.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 copyFile = (file: string) => {
  22. const filePath = path.resolve(__dirname, file)
  23. const basename = path.basename(file)
  24. if (!fs.existsSync(filePath)) {
  25. throw new Error(
  26. `${basename} not built. ` +
  27. `Run "nr build vue -f esm-browser" first.`
  28. )
  29. }
  30. this.emitFile({
  31. type: 'asset',
  32. fileName: basename,
  33. source: fs.readFileSync(filePath, 'utf-8')
  34. })
  35. }
  36. copyFile(`../vue/dist/vue.runtime.esm-browser.js`)
  37. copyFile(`../server-renderer/dist/server-renderer.esm-browser.js`)
  38. }
  39. }
  40. }