1.0.0 • Published 2 years ago

vite-plugin-godot v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

vite-plugin-godot

Embed and bundle Godot 4.x games using Vite.

npm license

The plugin allows you to export your Godot game directly to the public folder. The dev server will automatically include the appropriate headers that will make the page cross-origin isolated (required for SharedArrayBuffer).

See example in examples/vanilla.

Usage

Install the package:

npm install vite-plugin-godot -D

Add the plugin to vite.config.js:

import { defineConfig } from 'vite';
import godotPlugin from 'vite-plugin-godot';

export default defineConfig({
  plugins: [
    godotPlugin({
      // Set this to your exported name
      projectName: 'example2d',
      // Reload the page when detected changes in main.js
      reload: ['src/main.js'],
    }),
  ],
});

Make sure you have a canvas element somewhere in your DOM, then add the following to your index.html:

<script src="$GODOT_JS_FILE"></script>
<script>
  const GODOT_CONFIG = $GODOT_CONFIG;
  window.engine = new Engine(GODOT_CONFIG);
</script>

Now you can start the game in your script:

window.engine.startGame();

Export

Export the game using Web preset and set the directory to the public folder.

You can read more about exporting HTML in Godot docs.

License

This project is licensed under the MIT License.

1.0.0

2 years ago

0.1.0

2 years ago