实时对局选你的对手
加入
games
What shoal-games changes in this game
由 @shoal shoal 从 main 的 1b3bc26 分出 · 领先 1 个提交,比 main 落后 0 个
接续
贡献回去
55 行 · 2.4 KB 原始文件 永久链接 历史
1// The viewer: the upstream's React UI (its Vite, React and Linaria setup from vite.config.ts) with this folder's entry,
2// as static files with relative paths and no network: one script, one stylesheet, no CDN, no fonts to fetch. The art
3// pack (viewer/art/, built by src/art.py) is plain files beside them, linked from index.html.
4//
5// The look is 无名杀's (viewer/noname/): this folder's own table over the upstream's hooks and action building. When the
6// upstream's own components (its prompts, action bar and hand) import these modules, they get this folder's instead:
7// the image lookups (the art pack), the flying cards and the card face (drawn as 无名杀's; a card you play leaves your
8// hand for the middle of the table), and the style sheet (the same class names, restyled).
9import path from 'node:path';
10import { defineConfig, type Plugin } from 'vite';
11import react from '@vitejs/plugin-react';
12import wyw from '@wyw-in-js/vite';
13import { upstreamFixes } from './upstream-fixes';
14
15const NONAME = path.resolve('shoal/viewer/noname');
16const SWAPS: Record<string, string> = {
17 'src/client/assets/imageAssets': 'imageAssets.ts',
18 'src/client/utils/cardMoveAnimation': 'flyCards.ts',
19 'src/client/utils/cardFlyAnimation': 'flyCards.ts',
20 'src/client/components/CardFace': 'CardFace.tsx',
21 'src/client/components/gameViewStyles/index': 'styles.ts',
22};
23
24function swap(): Plugin {
25 return {
26 name: 'shoal-noname-swap',
27 enforce: 'pre',
28 async resolveId(source, importer, opts) {
29 if (!importer || importer.startsWith(NONAME)) return null;
30 const r = await this.resolve(source, importer, { ...opts, skipSelf: true });
31 const id = r?.id.replace(/\.tsx?$/, '');
32 const hit = id && Object.keys(SWAPS).find((k) => id.endsWith(k));
33 return hit ? path.join(NONAME, SWAPS[hit]) : null;
34 },
35 };
36}
37
38export default defineConfig({
39 root: 'shoal/viewer',
40 base: './',
41 publicDir: false,
42 plugins: [
43 upstreamFixes(),
44 swap(),
45 react({ exclude: ['node_modules/**'] }),
46 wyw({ sourceMap: false, displayName: false, exclude: ['node_modules/**'], evaluate: true, babelOptions: { presets: ['@babel/preset-typescript'] } }),
47 ],
48 build: {
49 outDir: '../../dist/shoal-viewer',
50 emptyOutDir: true,
51 target: 'es2022',
52 cssMinify: 'esbuild',
53 rollupOptions: { output: { codeSplitting: false, entryFileNames: 'viewer.js', assetFileNames: 'viewer[extname]' } },
54 },
55});