Add webpack

This commit is contained in:
Alex Page 2022-02-04 19:41:43 -05:00
parent ecd7c87e29
commit f08691a62e
10 changed files with 5421 additions and 43 deletions

3
.gitignore vendored
View file

@ -2,3 +2,6 @@
/target /target
.vscode .vscode
/pkg /pkg
node_modules
/dist
/wasm-pack.log

View file

@ -17,13 +17,19 @@ The goal is to closely mimic the look and behavior of the original game, but not
- Game speed will be fixed, possibly configurable - Game speed will be fixed, possibly configurable
- The original game's speed varied with CPU speed - The original game's speed varied with CPU speed
- Improve control response - Improve control response
- Support Windows, Linux, macOS - Support Windows, Linux, macOS, and the web
- Possibly web and mobile platforms too
## Building ## Building
1. [Install Rust](https://rustup.rs/) [Install Rust](https://rustup.rs/)
2. Run `cargo build` or `cargo run`
### Desktop
Run `cargo build` or `cargo run`
### Web
Run `npm run build` or `npm start`
## License ## License

View file

@ -1,39 +0,0 @@
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<style>
* {
margin: 0;
padding: 0;
}
body,
html {
height: 100%;
}
#canvas {
width: 100vw;
height: 56.25vw; /* height:width ratio = 9/16 = .5625 */
background: pink;
max-height: 100vh;
max-width: 177.78vh; /* 16/9 = 1.778 */
margin: auto;
position: absolute;
top: 0;
bottom: 0; /* vertical center */
left: 0;
right: 0; /* horizontal center */
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script src="./kroz.js"></script>
<script>
window.addEventListener("load", async () => {
await wasm_bindgen("./kroz_bg.wasm");
});
</script>
</body>
</html>

1
js/index.js Normal file
View file

@ -0,0 +1 @@
import("../pkg/index.js").catch(console.error);

5324
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

18
package.json Normal file
View file

@ -0,0 +1,18 @@
{
"author": "anpage <alex@anpage.me>",
"name": "kroz",
"version": "0.1.0",
"scripts": {
"build": "rimraf dist pkg && webpack",
"start": "rimraf dist pkg && webpack-dev-server --open -d",
"test": "cargo test && wasm-pack test --headless"
},
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "^1.1.0",
"copy-webpack-plugin": "^5.0.3",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.3",
"webpack-dev-server": "^3.7.1",
"rimraf": "^3.0.0"
}
}

View file

@ -28,6 +28,7 @@ impl GameState for State {
} }
impl State { impl State {
#[allow(dead_code)]
pub fn new(initialize_sound: bool) -> Self { pub fn new(initialize_sound: bool) -> Self {
let mut sound_output = if initialize_sound { let mut sound_output = if initialize_sound {
Some(SoundOutput::new()) Some(SoundOutput::new())

BIN
static/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

36
static/index.html Normal file
View file

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Kroz</title>
<link rel="icon" type="image/png" href="icon.png" />
<style>
* {
margin: 0;
padding: 0;
}
body,
html {
height: 100%;
}
#canvas {
width: 100vw;
height: 56.25vw;
max-height: 100vh;
max-width: 177.78vh;
margin: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script src="index.js"></script>
</body>
</html>

28
webpack.config.js Normal file
View file

@ -0,0 +1,28 @@
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const dist = path.resolve(__dirname, "dist");
module.exports = {
mode: "production",
entry: {
index: "./js/index.js"
},
output: {
path: dist,
filename: "[name].js"
},
devServer: {
contentBase: dist,
},
plugins: [
new CopyPlugin([
path.resolve(__dirname, "static")
]),
new WasmPackPlugin({
crateDirectory: __dirname,
}),
]
};