Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 构建工具增加vite #213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
734 changes: 1 addition & 733 deletions package-lock.json

Large diffs are not rendered by default.

1,308 changes: 1,308 additions & 0 deletions src/server/package-lock.json

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions src/ui/platforms/desktop/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=0.5" />
<meta name="theme-color" content="#000000" />
<title>新神杀</title>
<meta name="keywords" content="新神杀,三国杀,太阳神三国杀,神杀" />
<meta
name="description"
content="新神杀 - 瑾此纪念太阳神三国杀十周年"
/>
<link rel="apple-touch-icon" href="/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
</head>
<body>
<script src="./src/index.tsx" type="module"></script>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
19,251 changes: 19,251 additions & 0 deletions src/ui/platforms/desktop/package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/ui/platforms/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"bfj": "^7.0.2",
"camelcase": "^6.1.0",
"case-sensitive-paths-webpack-plugin": "2.3.0",
"chalk": "^4.1.2",
"classnames": "^2.2.6",
"cra-template-typescript": "1.1.2",
"css-loader": "4.3.0",
Expand Down Expand Up @@ -85,6 +86,8 @@
"workbox-webpack-plugin": "5.1.4"
},
"scripts": {
"vite:dev": "vite dev --host",
"vite:build": "vite build",
"patch": "ts-node -P ../../../../tsconfig.json ../../../pre_release.ts",
"sync:mac": "rm -rf ./src/core ./build && cp -R ../../../core ./src",
"sync:win": "rimraf ./src/core ./build && xcopy ..\\..\\..\\core .\\src\\core /s /i",
Expand Down Expand Up @@ -157,6 +160,7 @@
"@types/react-router-dom": "^5.1.3",
"@types/react-test-renderer": "^16.9.2",
"@types/socket.io-client": "^1.4.32",
"@vitejs/plugin-react": "^1.3.2",
"create-react-app": "^4.0.3",
"cross-env": "^7.0.2",
"css-loader": "^3.4.2",
Expand All @@ -167,7 +171,8 @@
"react-test-renderer": "^16.13.0",
"rimraf": "^3.0.0",
"ts-loader": "^6.2.1",
"typescript": "^4.3.5"
"typescript": "^4.3.5",
"vite": "^2.9.13"
},
"resolutions": {
"react-dev-utils": "10.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class DevImageLoader implements ImageLoader {
throw Precondition.UnreachableError(section);
}

const image: string = (await import(`${remoteRoot}/images/slim_equips/${sectionName}.png`)).default;
const image: string = (await import(/* @vite-ignore */ `${remoteRoot}/images/slim_equips/${sectionName}.png`)).default;
return { alt: 'Aborted Slim Equip Card', src: image };
}

Expand Down
3 changes: 2 additions & 1 deletion src/ui/platforms/desktop/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { emojiLoader } from './emoji_loader/emoji_loader';
import './index.css';
import * as serviceWorker from './serviceWorker';

const mode = (process.env.REACT_APP_DEV_MODE as ClientFlavor) || ClientFlavor.Dev;
// const mode = (process.env.REACT_APP_DEV_MODE as ClientFlavor) || ClientFlavor.Dev;
const mode = ClientFlavor.Dev
const config = getClientConfig(mode);

if (config.flavor !== ClientFlavor.Web) {
Expand Down
21 changes: 13 additions & 8 deletions src/ui/platforms/desktop/tools/replay.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as crypto from 'crypto';
import * as stringCompressor from 'shrink-string';
// import * as stringCompressor from 'shrink-string';

export type ReplayOtherInfo = {
gameInfo: object;
Expand Down Expand Up @@ -39,20 +39,25 @@ export class Replay {
let encryptedVersion = cipher.update(this.otherInfo!.version);
encryptedVersion = Buffer.concat([encryptedVersion, cipher.final()]);
this.otherInfo!.version = encryptedVersion.toString('hex');
return await stringCompressor.compress(
JSON.stringify({
events: this.gameEvents,
otherInfo: this.otherInfo,
}),
);
// return await stringCompressor.compress(
// JSON.stringify({
// events: this.gameEvents,
// otherInfo: this.otherInfo,
// }),
// );
return JSON.stringify({
events: this.gameEvents,
otherInfo: this.otherInfo,
});
}

public async parse(rawData: string): Promise<object> {
let data: any;
try {
data = JSON.parse(rawData);
} catch {
const rawJsonString = await stringCompressor.decompress(rawData);
// const rawJsonString = await stringCompressor.decompress();
const rawJsonString = rawData;
data = JSON.parse(rawJsonString);
}

Expand Down
29 changes: 29 additions & 0 deletions src/ui/platforms/desktop/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from "path"
const alias = ['core','props','ui','assets','services','pages','utils','audio_loader','image_loader','electron_loader','languages','electron.port','client.config'].reduce((perv,item)=>{
perv[item] = path.resolve(__dirname,`src/${item}`);
return perv
},{})
// https://vitejs.dev/config/
export default defineConfig({
define: {
global: "globalThis",
},
esbuild: {
define: {
this: 'window'
}
},
plugins: [react({
babel: {
parserOpts: { plugins: ["decorators-legacy"] },
},
})],
resolve:{
alias:{
...alias,
"xmlhttprequest-ssl": "./node_modules/engine.io-client/lib/xmlhttprequest.js"
}
}
})