@@ -13,11 +13,15 @@ import Layouts from 'vite-plugin-vue-layouts'
1313
1414import { Download } from '@proj-airi/unplugin-fetch/vite'
1515import { DownloadLive2DSDK } from '@proj-airi/unplugin-live2d-sdk/vite'
16+ import { createS3Provider , WarpDrivePlugin } from '@proj-airi/vite-plugin-warpdrive'
1617import { templateCompilerOptions } from '@tresjs/core'
1718import { LFS , SpaceCard } from 'hfup/vite'
1819import { defineConfig } from 'vite'
1920import { VitePWA } from 'vite-plugin-pwa'
2021
22+ const stageUIAssetsRoot = resolve ( join ( import . meta. dirname , '..' , '..' , 'packages' , 'stage-ui' , 'src' , 'assets' ) )
23+ const sharedCacheDir = resolve ( join ( import . meta. dirname , '..' , '..' , '.cache' ) )
24+
2125export default defineConfig ( {
2226 optimizeDeps : {
2327 exclude : [
@@ -63,6 +67,7 @@ export default defineConfig({
6367 ] ,
6468 } ,
6569 } ,
70+
6671 plugins : [
6772 Info ( ) ,
6873
@@ -153,10 +158,10 @@ export default defineConfig({
153158 VueDevTools ( ) ,
154159
155160 DownloadLive2DSDK ( ) ,
156- Download ( 'https://dist.ayaka.moe/live2d-models/hiyori_free_zh.zip' , 'hiyori_free_zh.zip' , 'assets/ live2d/models' ) ,
157- Download ( 'https://dist.ayaka.moe/live2d-models/hiyori_pro_zh.zip' , 'hiyori_pro_zh.zip' , 'assets/ live2d/models' ) ,
158- Download ( 'https://dist.ayaka.moe/vrm-models/VRoid-Hub/AvatarSample-A/AvatarSample_A.vrm' , 'AvatarSample_A.vrm' , 'assets/ vrm/models/AvatarSample-A' ) ,
159- Download ( 'https://dist.ayaka.moe/vrm-models/VRoid-Hub/AvatarSample-B/AvatarSample_B.vrm' , 'AvatarSample_B.vrm' , 'assets/ vrm/models/AvatarSample-B' ) ,
161+ Download ( 'https://dist.ayaka.moe/live2d-models/hiyori_free_zh.zip' , 'hiyori_free_zh.zip' , 'live2d/models' , { parentDir : stageUIAssetsRoot , cacheDir : sharedCacheDir } ) ,
162+ Download ( 'https://dist.ayaka.moe/live2d-models/hiyori_pro_zh.zip' , 'hiyori_pro_zh.zip' , 'live2d/models' , { parentDir : stageUIAssetsRoot , cacheDir : sharedCacheDir } ) ,
163+ Download ( 'https://dist.ayaka.moe/vrm-models/VRoid-Hub/AvatarSample-A/AvatarSample_A.vrm' , 'AvatarSample_A.vrm' , 'vrm/models/AvatarSample-A' , { parentDir : stageUIAssetsRoot , cacheDir : sharedCacheDir } ) ,
164+ Download ( 'https://dist.ayaka.moe/vrm-models/VRoid-Hub/AvatarSample-B/AvatarSample_B.vrm' , 'AvatarSample_B.vrm' , 'vrm/models/AvatarSample-B' , { parentDir : stageUIAssetsRoot , cacheDir : sharedCacheDir } ) ,
160165
161166 // HuggingFace Spaces
162167 LFS ( { root : cwd ( ) , extraGlobs : [ '*.vrm' , '*.vrma' , '*.hdr' , '*.cmo3' , '*.png' , '*.jpg' , '*.jpeg' , '*.gif' , '*.webp' , '*.bmp' , '*.ttf' ] } ) ,
@@ -175,5 +180,47 @@ export default defineConfig({
175180 ] ,
176181 short_description : 'AI driven VTuber & Companion, supports Live2D and VRM.' ,
177182 } ) ,
183+
184+ // For the following example assets:
185+ //
186+ // dist/assets/ort-wasm-simd-threaded.jsep-B0T3yYHD.wasm 21,596.01 kB │ gzip: 5,121.95 kB
187+ // dist/assets/XiaolaiSC-Regular-SNWuh554.ttf 22,183.94 kB
188+ // dist/assets/cjkFonts_allseto_v1.11-ByBdljxl.ttf 31,337.14 kB
189+ // dist/assets/duckdb-coi-CSr8FQO4.wasm 32,320.49 kB │ gzip: 7,194.65 kB
190+ // dist/assets/duckdb-eh-BJOC5S4x.wasm 32,604.02 kB │ gzip: 7,133.37 kB
191+ // dist/assets/duckdb-mvp-8HYqhb4i.wasm 37,345.64 kB │ gzip: 8,099.69 kB
192+ //
193+ // they are too large to be able to put into deployments like Cloudflare Workers or Pages,
194+ // we need to upload them to external storage and use renderBuiltUrl to rewrite their URLs.
195+ ...( ( ! env . S3_ENDPOINT || ! env . S3_ACCESS_KEY_ID || ! env . S3_SECRET_ACCESS_KEY )
196+ ? [ ]
197+ : [
198+ WarpDrivePlugin ( {
199+ prefix : 'proj-airi/stage-web/' ,
200+ include : [ / \. w a s m $ / i, / \. t t f $ / i, / \. v r m $ / i, / \. z i p $ / i] , // in existing assets, wasm, ttf, vrm files are the largest ones
201+ manifest : true ,
202+ contentTypeBy : ( filename : string ) => {
203+ if ( filename . endsWith ( '.wasm' ) ) {
204+ return 'application/wasm'
205+ }
206+ if ( filename . endsWith ( '.ttf' ) ) {
207+ return 'font/ttf'
208+ }
209+ if ( filename . endsWith ( '.vrm' ) ) {
210+ return 'application/octet-stream'
211+ }
212+ if ( filename . endsWith ( '.zip' ) ) {
213+ return 'application/zip'
214+ }
215+ } ,
216+ provider : createS3Provider ( {
217+ endpoint : env . S3_ENDPOINT ,
218+ accessKeyId : env . S3_ACCESS_KEY_ID ,
219+ secretAccessKey : env . S3_SECRET_ACCESS_KEY ,
220+ region : env . S3_REGION ,
221+ publicBaseUrl : env . WARP_DRIVE_PUBLIC_BASE ?? env . S3_ENDPOINT ,
222+ } ) ,
223+ } ) ,
224+ ] ) ,
178225 ] ,
179226} )
0 commit comments