For AI agents: the complete documentation index is available at /vue-vrm/zh/llms.txt, the full documentation bundle is available at /vue-vrm/zh/llms-full.txt, and this page is available as Markdown at /vue-vrm/zh/guide/bundling.md.
  • 简体中文
  • 打包技巧

    three.js 和 three-vrm 体积较大。把它们拆分成独立的 chunk,可以减小主包体积,并让浏览器单独缓存。

    Vite

    // vite.config.ts
    import { defineConfig } from 'vite';
    
    export default defineConfig({
      build: {
        rollupOptions: {
          output: {
            manualChunks(id) {
              if (id.includes('/node_modules/three/')) return 'three';
              if (id.includes('/node_modules/@pixiv/')) return 'three-vrm';
            }
          }
        }
      }
    });

    Rsbuild

    // rsbuild.config.ts
    import { defineConfig } from '@rsbuild/core';
    
    export default defineConfig({
      splitChunks: {
        cacheGroups: {
          three: {
            test: /node_modules[\\/](three|@pixiv)[\\/]/,
            name: 'three',
            chunks: 'all'
          }
        }
      }
    });

    懒加载

    如果首屏不需要头像,可以异步加载组件:

    import { defineAsyncComponent } from 'vue';
    
    const VrmCanvas = defineAsyncComponent(async () => (await import('vue-vrm')).VrmCanvas);