vite.config.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /// <reference types="vitest" />
  2. import fs from 'fs'
  3. import { defineConfig } from 'vite'
  4. import vue from '@vitejs/plugin-vue'
  5. import banner from 'vite-plugin-banner'
  6. import Inspect from 'vite-plugin-inspect'
  7. import dts from 'vite-plugin-dts'
  8. import copy from 'rollup-plugin-copy'
  9. /* import analyze from 'rollup-plugin-analyzer'
  10. */ /* import { visualizer } from 'rollup-plugin-visualizer' */
  11. import { resolve, join } from 'pathe'
  12. import { lightGreen, yellow, gray, bold } from 'kolorist'
  13. import { ViteTresPlugin } from './plugins/vite-tres-types-plugin'
  14. import pkg from './package.json'
  15. // eslint-disable-next-line no-console
  16. console.log(`${lightGreen('▲')} ${gray('■')} ${yellow('●')} ${bold('Tres')} v${pkg.version}`)
  17. // https://vitejs.dev/config/
  18. export default defineConfig({
  19. server: {
  20. port: 5174,
  21. },
  22. resolve: {
  23. dedupe: ['@tresjs/cientos'],
  24. },
  25. plugins: [
  26. vue({
  27. isProduction: false,
  28. template: {
  29. compilerOptions: {
  30. isCustomElement: tag => tag.startsWith('Tres') && tag !== 'TresCanvas',
  31. },
  32. },
  33. }),
  34. dts({
  35. insertTypesEntry: true,
  36. afterBuild() {
  37. console.log('🪄 ✨ Magically generating types for TresJS')
  38. const outputDir = join(__dirname, 'dist/types')
  39. const outputFile = join(outputDir, 'index.d.ts')
  40. if (fs.existsSync(outputFile)) {
  41. const index = fs.readFileSync(outputFile, 'utf-8')
  42. fs.writeFileSync(outputFile, `import './tres-components';\n${index}`)
  43. }
  44. },
  45. }),
  46. ViteTresPlugin(),
  47. banner({
  48. content: `/**\n * name: ${pkg.name}\n * version: v${
  49. pkg.version
  50. }\n * (c) ${new Date().getFullYear()}\n * description: ${pkg.description}\n * author: ${pkg.author}\n */`,
  51. }),
  52. Inspect(),
  53. ],
  54. test: {
  55. environment: 'jsdom',
  56. globals: true,
  57. threads: false,
  58. },
  59. build: {
  60. lib: {
  61. entry: resolve(__dirname, 'src/index.ts'),
  62. name: 'tres',
  63. fileName: 'tres',
  64. },
  65. watch: {
  66. include: [resolve(__dirname, 'src')],
  67. },
  68. copyPublicDir: false,
  69. rollupOptions: {
  70. plugins: [
  71. copy({
  72. targets: [{ src: 'src/types/tres-components.d.ts', dest: 'dist/types' }],
  73. }),
  74. /* analyze(), */
  75. /* visualizer({
  76. open: true,
  77. gzipSize: true,
  78. brotliSize: true,
  79. }), */
  80. ],
  81. external: ['vue', '@vueuse/core', 'three'],
  82. output: {
  83. exports: 'named',
  84. // Provide global variables to use in the UMD build
  85. // for externalized deps
  86. globals: {
  87. vue: 'Vue',
  88. '@vueuse/core': 'VueUseCore',
  89. three: 'Three',
  90. },
  91. },
  92. },
  93. },
  94. optimizeDeps: {
  95. exclude: ['vue', 'three'],
  96. },
  97. })