Ship your game
Build your game into a folder that opens from disk or a static host, with pictures, sound and saves that work there.
Use this when the game is ready for players, as a folder to zip, upload to itch.io or open by double-clicking index.html. A game made with Create a game has everything it needs. Why IFLoom works this way explains why a page opened from disk loads nothing at runtime.
Prepare the game
-
Keep the Vite preset. A new game's
vite.config.tshas it already. Otherwise add it, with your UI framework's Vite plugin invite.plugins:// vite.config.ts import { ifloom } from '@ifloom/cli/vite' export default ifloom()The preset builds with
base: './'and puts the script and the stylesheet insideindex.html, so the page loads no other file of its own. -
Put pictures in
public/art/and sound inpublic/audio/. Vite copiespublic/into the build, so they land beside the page. Name them by relative path,art/cafe.jpg, never/art/cafe.jpg: a leading slash points at the root of the drive, or of the host on itch.io. -
Load nothing at runtime. Import your content statically, and don't call
fetch()or a dynamicimport()in your own code.ifloom builddoesn't search for them, and they fail on a page opened from disk. -
Leave the debug plugin out. Add it only when
import.meta.env.DEVistrue, which it isn't underifloom build(see Debug a game). -
Give the game an id of its own.
saveskeys every save with the game'sid, as incorner-cafe.save.auto, so two games on one origin don't overwrite each other. Changing the id later loses every player's saves.
Choose where saves go
browserRunner, which every template uses, keeps saves in localStorage. Choose a driver for how the game ships:
- A short game in a browser or on itch.io keeps
localStorageDriver(), with about 5MB. - A long game, or one with big backlogs or mods, passes
indexedDbDriver(), which has much more room. - A desktop wrapper such as Tauri or Electron passes a driver of its own over the wrapper's files (see Write a save driver).
Pass the driver in the runner's options. With the React UI's mountGame, pass them as runner:
// src/main.ts
import { browserRunner, indexedDbDriver } from '@ifloom/browser'
import { saves } from '@ifloom/engine'
import module from './game.ts'
const { game } = module.build()
const runner = await browserRunner(game, { saves: saves(game, indexedDbDriver()) })Browser storage goes when the player clears site data. Offer an export and an import with exportSlot and importText (see Saves), so players can keep their saves.
Build it
Check the content, then build:
npm run check
npm run buildifloom build builds the game into dist/, or the folder --out names. It then checks the folder: an index.html, every script and stylesheet it loads beside it, and every picture, video and sound the game names. It prints each problem and exits with 1, so a CI job fails on a build that wouldn't open from disk.
Check it worked
Open dist/index.html straight from disk, by double-clicking it. Don't test only through vite preview, because a local server isn't file:// and hides what fails there. Play past the first scene, save, reload the page and load the save.
To upload to itch.io, zip the contents of dist/ and upload the zip as an HTML game.
Variations
One file, pictures and all. ifloom build --inline-assets puts every picture inside index.html and removes art/, for a game to attach to a message or upload where only one file goes. Sound and video stay beside it, so a game with sound is always a folder.
Without the CLI. Write the preset out in your own Vite config, with base: './' and vite-plugin-singlefile, and build with vite build. checkBuild from @ifloom/cli runs the same check from a script of your own.
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import { viteSingleFile } from 'vite-plugin-singlefile'
export default defineConfig({
base: './',
plugins: [react(), tailwindcss(), viteSingleFile()],
})Another bundler. Build with esbuild and Build with webpack make the same single file. Build with Next.js can't, so a game built with Next is played on its website.
For more, see:
ifloom buildand the Vite preset.- Saves and the save drivers.
- Nothing loads at runtime.
Last updated on