You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

  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: [
  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.runtime.esm-browser.js`)
  47. copyFile(`../server-renderer/dist/server-renderer.esm-browser.js`)
  48. }
  49. }
  50. }