Skip to content

Commit cf52d18

Browse files
committed
Use Webpack
1 parent bd3e40d commit cf52d18

20 files changed

+1209
-41
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
node_modules
3+
dist
34
engine.exe
45
_*

index.html

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>Chess Analyser</title>
6+
7+
<link rel="stylesheet" type="text/css" href="node_modules/chessground/assets/chessground.base.css" />
8+
<link rel="stylesheet" type="text/css" href="node_modules/chessground/assets/chessground.brown.css" />
9+
<link rel="stylesheet" type="text/css" href="node_modules/chessground/assets/chessground.cburnett.css" />
10+
11+
<link rel="stylesheet" type="text/css" href="src/index.css" />
12+
13+
<script type="module" src="dist/app.js"></script>
14+
</head>
15+
<body>
16+
<div id="app"></div>
17+
</body>
18+
</html>

main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ app.whenReady().then(async () => {
3232
const live_analysis_engine = new Engine((...args) => window.webContents.send('evaluation-callback', ...args));
3333
ipcMain.handle('evaluate-for-live-analysis', async (event, ...args) => live_analysis_engine.evaluate(...args));
3434

35-
await window.loadFile('src/index.html');
35+
await window.loadFile('index.html');
3636
});

package-lock.json

+1,132-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
},
2929
"scripts": {
3030
"test": "vitest",
31+
"watch": "webpack --mode=development --watch",
32+
"build": "webpack --mode=production",
3133
"start": "electron ."
3234
},
3335
"dependencies": {
@@ -38,7 +40,9 @@
3840
"electron-store": "^8.1.0",
3941
"lodash-es": "^4.17.21",
4042
"tinycolor2": "^1.6.0",
41-
"vue": "^3.3.4"
43+
"vue": "^3.3.4",
44+
"webpack": "^5.90.2",
45+
"webpack-cli": "^5.1.4"
4246
},
4347
"devDependencies": {
4448
"vitest": "^0.32.0"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/components/MaterialDifferencePanel.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

2+
import { PIECE_VALUES } from '@/material.js';
3+
24
export default {
35
template: `
46
<div class="flex-row" style="height: 30px; gap: 15px; align-items: center">
57
<div v-for="(count, type) in material_difference[color]">
68
<img
79
v-for="_ in count"
810
:alt="type"
9-
:src="'../assets/piece/' + type + '.svg'"
11+
:src="images[type]"
1012
style="height: 30px; margin-right: -10px"
1113
/>
1214
</div>
@@ -19,9 +21,18 @@ export default {
1921
props: {
2022
color: { type: String, required: true, validator: value => ['white', 'black'].includes(value) },
2123
},
24+
data: () => ({
25+
images: {},
26+
}),
2227
computed: {
2328
value() {
2429
return this.material_difference.value * (this.color === 'white' ? 1 : -1);
2530
},
2631
},
32+
async created() {
33+
await Promise.all(Object.keys(PIECE_VALUES).map(async type => {
34+
const image_module = await import(`@/assets/piece/${type}.svg`);
35+
this.images[type] = image_module.default;
36+
}));
37+
},
2738
};

src/index.html

-18
This file was deleted.

src/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
import { Chess, DEFAULT_POSITION } from '../node_modules/chess.js/dist/esm/chess.js';
3-
import Chessground from '../node_modules/chessground/index.js';
4-
import { computed as vue_computed, createApp } from '../node_modules/vue/dist/vue.esm-browser.js';
2+
import { Chess, DEFAULT_POSITION } from 'chess.js';
3+
import { Chessground } from 'chessground';
4+
import { computed as vue_computed, createApp } from 'vue/dist/vue.esm-bundler.js';
55

66
import ActionPanel from './components/ActionPanel.js';
77
import AnalysisPanel from './components/AnalysisPanel.js';
@@ -315,16 +315,17 @@ const app = createApp({
315315
},
316316
});
317317
},
318-
playSound(san) {
318+
async playSound(san) {
319319
let name;
320320
if (san.includes('x')) {
321321
name = 'capture';
322322
} else {
323323
name = 'move';
324324
}
325-
const audio = new Audio(`../assets/sound/${name}.mp3`);
325+
const sound_module = await import(`@/assets/sound/${name}.mp3`);
326+
const audio = new Audio(sound_module.default);
326327
audio.volume = 0.7;
327-
audio.play();
328+
await audio.play();
328329
},
329330
update() {
330331
this.updateEvaluation();

src/material.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
import { Chess } from '../node_modules/chess.js/dist/esm/chess.js';
2+
import { Chess } from 'chess.js';
33

4-
const PIECE_VALUES = { Q: 9, R: 5, B: 3, N: 3, P: 1 };
4+
export const PIECE_VALUES = { Q: 9, R: 5, B: 3, N: 3, P: 1 };
55

66

77
export function calculateMaterialDifference(chess) {

src/review.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import tinycolor from '../node_modules/tinycolor2/esm/tinycolor.js';
2+
import tinycolor from 'tinycolor2';
33

44
const ADVANTAGE_CUTOFF = 10;
55
const SENSITIVITY_DIVIDER = 2.5;

webpack.config.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
import path from 'path';
3+
4+
import webpack from 'webpack';
5+
6+
export default {
7+
entry: {
8+
app: path.resolve('src/index.js'),
9+
},
10+
resolve: {
11+
alias: {
12+
'@': path.resolve('src/'),
13+
},
14+
},
15+
module: {
16+
rules: [
17+
{
18+
test: /\.(mp3|svg)$/,
19+
type: 'asset/resource',
20+
},
21+
],
22+
},
23+
plugins: [
24+
new webpack.DefinePlugin({
25+
// https://github.com/vuejs/core/tree/main/packages/vue#bundler-build-feature-flags
26+
__VUE_OPTIONS_API__: true,
27+
__VUE_PROD_DEVTOOLS__: false,
28+
}),
29+
],
30+
};

0 commit comments

Comments
 (0)