vite.config.ts 2.8 KB

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