Skip to content

itsKaynine/vite-plugin-godot

Repository files navigation

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.

About

Embed and bundle Godot 4.x games using Vite

Resources

License

Stars

Watchers

Forks

Packages

No packages published