| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | import path from 'node:path'; |
| 10 | import { defineConfig, type Plugin } from 'vite'; |
| 11 | import react from '@vitejs/plugin-react'; |
| 12 | import wyw from '@wyw-in-js/vite'; |
| 13 | |
| 14 | const NONAME = path.resolve('shoal/viewer/noname'); |
| 15 | const SWAPS: Record<string, string> = { |
| 16 | 'src/client/assets/imageAssets': 'imageAssets.ts', |
| 17 | 'src/client/utils/cardMoveAnimation': 'flyCards.ts', |
| 18 | 'src/client/utils/cardFlyAnimation': 'flyCards.ts', |
| 19 | 'src/client/components/CardFace': 'CardFace.tsx', |
| 20 | 'src/client/components/gameViewStyles/index': 'styles.ts', |
| 21 | }; |
| 22 | |
| 23 | function swap(): Plugin { |
| 24 | return { |
| 25 | name: 'shoal-noname-swap', |
| 26 | enforce: 'pre', |
| 27 | async resolveId(source, importer, opts) { |
| 28 | if (!importer || importer.startsWith(NONAME)) return null; |
| 29 | const r = await this.resolve(source, importer, { ...opts, skipSelf: true }); |
| 30 | const id = r?.id.replace(/\.tsx?$/, ''); |
| 31 | const hit = id && Object.keys(SWAPS).find((k) => id.endsWith(k)); |
| 32 | return hit ? path.join(NONAME, SWAPS[hit]) : null; |
| 33 | }, |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | export default defineConfig({ |
| 38 | root: 'shoal/viewer', |
| 39 | base: './', |
| 40 | publicDir: false, |
| 41 | plugins: [ |
| 42 | swap(), |
| 43 | react({ exclude: ['node_modules/**'] }), |
| 44 | wyw({ sourceMap: false, displayName: false, exclude: ['node_modules/**'], evaluate: true, babelOptions: { presets: ['@babel/preset-typescript'] } }), |
| 45 | ], |
| 46 | build: { |
| 47 | outDir: '../../dist/shoal-viewer', |
| 48 | emptyOutDir: true, |
| 49 | target: 'es2022', |
| 50 | cssMinify: 'esbuild', |
| 51 | rollupOptions: { output: { codeSplitting: false, entryFileNames: 'viewer.js', assetFileNames: 'viewer[extname]' } }, |
| 52 | }, |
| 53 | }); |