Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.
/ webgm Public archive
forked from luizzeroxis/webgm

Commit 25a491b

Browse files
committed
Preparations for stand alone export: game and common folders are now separate chunks, and a new game.html file is created.
1 parent f70a44a commit 25a491b

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

src/index-game.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Entry point for the standalone game build
2+
3+
import ProjectSerializer from "./common/ProjectSerializer.js";
4+
import Game from "./game/Game.js";
5+
6+
async function main() {
7+
if (window.location.protocol == "file:") {
8+
document.body.innerHTML += "<p>Opening the game from your local system is not supported. Please create a local server instead.</p>";
9+
}
10+
11+
let response;
12+
let projectZip;
13+
14+
try {
15+
response = await fetch("project.zip");
16+
projectZip = await response.blob();
17+
} catch (e) {
18+
console.error(e);
19+
}
20+
21+
if (!response?.ok) {
22+
document.body.innerHTML += "<p>Error: Cannot load project.zip!</p>";
23+
return;
24+
}
25+
26+
const project = await ProjectSerializer.unserializeZIP(projectZip);
27+
28+
const canvas = document.createElement("canvas");
29+
canvas.width = 640;
30+
canvas.height = 480;
31+
canvas.tabIndex = 0;
32+
document.body.append(canvas);
33+
34+
canvas.focus({preventScroll: true});
35+
36+
const game = new Game({
37+
project: project,
38+
canvas: canvas,
39+
input: canvas,
40+
menuManager: null,
41+
});
42+
43+
game.start();
44+
45+
window.game = game;
46+
}
47+
48+
main();

webpack.common.js

+24-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const webpack = require("webpack");
1111
const gitRevisionPlugin = new GitRevisionPlugin();
1212

1313
module.exports = {
14-
entry: "./src/index.js",
14+
entry: {
15+
"main": "./src/index.js",
16+
"main-game": "./src/index-game.js",
17+
},
1518
output: {
1619
path: path.resolve(__dirname, "dist"),
1720
filename: "[name].bundle.js",
@@ -43,21 +46,28 @@ module.exports = {
4346
optimization: {
4447
runtimeChunk: "single",
4548
splitChunks: {
49+
chunks: "all", // insurance
4650
cacheGroups: {
47-
vendor: {
51+
vendors: {
4852
test: /[\\/]node_modules[\\/]/,
4953
name: "vendors",
50-
chunks: "all",
5154
},
52-
image: {
55+
images: {
5356
test(module) {
5457
return (
5558
module.resource
5659
&& module.resource.endsWith(".png")
5760
);
5861
},
5962
name: "images",
60-
chunks: "all",
63+
},
64+
game: {
65+
test: /[\\/]src[\\/]game[\\/]/,
66+
name: "game",
67+
},
68+
common: { // technically, this could be in 'game', but it's probably good to be separate
69+
test: /[\\/]src[\\/]common[\\/]/,
70+
name: "common",
6171
},
6272
},
6373
},
@@ -69,12 +79,18 @@ module.exports = {
6979
"LASTCOMMITDATETIME": JSON.stringify(gitRevisionPlugin.lastcommitdatetime()),
7080
},
7181
}),
82+
new ESLintPlugin({
83+
files: path.resolve(__dirname, "."),
84+
}),
7285
new HtmlWebpackPlugin({
7386
title: "webgm",
87+
excludeChunks: ["main-game"],
7488
}),
75-
new MiniCssExtractPlugin(),
76-
new ESLintPlugin({
77-
files: path.resolve(__dirname, "."),
89+
new HtmlWebpackPlugin({
90+
filename: "game.html",
91+
title: "webgm game",
92+
chunks: ["main-game"],
7893
}),
94+
new MiniCssExtractPlugin(),
7995
],
8096
};

webpack.prod.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = mergeWithRules({
2121
{
2222
test: /\.[s]css$/,
2323
use: [
24-
MiniCssExtractPlugin.loader,
24+
// MiniCssExtractPlugin.loader,
25+
"style-loader", // temporarily using this for standalone reasons
2526
],
2627
},
2728
],

0 commit comments

Comments
 (0)