2
0

vite.config.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 { execaSync } from 'execa'
  6. const commit = execaSync('git', ['rev-parse', '--short=7', 'HEAD']).stdout
  7. export default defineConfig({
  8. plugins: [
  9. vue({
  10. script: {
  11. fs: {
  12. fileExists: fs.existsSync,
  13. readFile: file => fs.readFileSync(file, 'utf-8')
  14. }
  15. }
  16. }),
  17. copyVuePlugin()
  18. ],
  19. define: {
  20. __COMMIT__: JSON.stringify(commit),
  21. __VUE_PROD_DEVTOOLS__: JSON.stringify(true)
  22. },
  23. optimizeDeps: {
  24. exclude: ['@vue/repl']
  25. }
  26. })
  27. function copyVuePlugin(): Plugin {
  28. return {
  29. name: 'copy-vue',
  30. generateBundle() {
  31. const copyFile = (file: string) => {
  32. const filePath = path.resolve(__dirname, file)
  33. const basename = path.basename(file)
  34. if (!fs.existsSync(filePath)) {
  35. throw new Error(
  36. `${basename} not built. ` +
  37. `Run "nr build vue -f esm-browser" first.`
  38. )
  39. }
  40. this.emitFile({
  41. type: 'asset',
  42. fileName: basename,
  43. source: fs.readFileSync(filePath, 'utf-8')
  44. })
  45. }
  46. copyFile(`../vue/dist/vue.esm-browser.js`)
  47. copyFile(`../vue/dist/vue.esm-browser.prod.js`)
  48. copyFile(`../vue/dist/vue.runtime.esm-browser.js`)
  49. copyFile(`../vue/dist/vue.runtime.esm-browser.prod.js`)
  50. copyFile(`../server-renderer/dist/server-renderer.esm-browser.js`)
  51. }
  52. }
  53. }