Skip to content

Commit

Permalink
Fix web build
Browse files Browse the repository at this point in the history
  • Loading branch information
benfrankel committed Jul 7, 2024
1 parent 6d7071c commit e44c721
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
27 changes: 20 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@ use bevy::prelude::*;

fn main() {
App::new()
// Wasm builds will check for meta files (that don't exist) if this isn't set.
// This causes errors and even panics on web build on itch.
// See https://github.com/bevyengine/bevy_github_ci_template/issues/48.
.add_plugins(DefaultPlugins.set(AssetPlugin {
meta_check: AssetMetaCheck::Never,
..default()
}))
.add_plugins(
DefaultPlugins
.set(AssetPlugin {
// Wasm builds will check for meta files (that don't exist) if this isn't set.
// This causes errors and even panics on web build on itch.
// See https://github.com/bevyengine/bevy_github_ci_template/issues/48.
meta_check: AssetMetaCheck::Never,
..default()
})
.set(WindowPlugin {
primary_window: Some(Window {
title: "bevy-template".to_string(),
canvas: Some("#bevy".to_string()),
fit_canvas_to_parent: true,
prevent_default_event_handling: true,
..default()
}),
..default()
}),
)
// We separate Bevy configuration from our game configuration.
.add_plugins(core::plugin)
.run();
Expand Down
17 changes: 13 additions & 4 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<!doctype html>
<html lang="en">

<body style="margin: 0px;">
<head>
<meta charset="utf-8" />
<title>bevy-template</title>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<canvas id="bevy">
Javascript and canvas support is required
</canvas>

<script type="module">
import './restart-audio-context.js'
import init from './bevy_game.js'

import init from './bevy_template.js'
init().catch((error) => {
if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) {
throw error;
Expand All @@ -14,4 +23,4 @@
</script>
</body>

</html>
</html>
11 changes: 11 additions & 0 deletions web/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* {
margin: 0;
padding: 0;
border: 0;
}

html,
body {
width: 100%;
height: 100%;
}

0 comments on commit e44c721

Please sign in to comment.