@im-nassinger/vite-plugin-openfl
v0.5.0
Published
Vite plugin that resolves OpenFL's namespace and generated class modules for use with npm bundling.
Readme
@g.nassinger/vite-plugin-openfl
A Vite plugin that lets Vite resolve OpenFL's
namespace imports (openfl/display, openfl/events, etc.) and generated
class modules when OpenFL is installed as an npm dependency.
Install
npm install --save-dev @g.nassinger/vite-plugin-openflopenfl and vite are peer dependencies and must already be installed in
your project.
Usage
Add the plugin to your vite.config.ts:
import { defineConfig } from "vite";
import openfl from "@g.nassinger/vite-plugin-openfl";
export default defineConfig({
plugins: [openfl()]
});That's it. Once added, you can import OpenFL modules directly:
import { Sprite } from "openfl/display";What it does
OpenFL ships its compiled output as a set of Haxe-generated CommonJS modules
addressed through a custom path-mapping table rather than a conventional
exports map. This plugin reads that table at Vite config time and
registers two sets of resolve.alias entries so Vite's resolver understands
those paths:
- Namespace aliases — maps specifiers like
openfl/displayto their underlying directory inopenfl's package output. - Class aliases — generates small CommonJS shim files (cached under
node_modules/.openfl-vite-shims) that re-export each generated class's default export, then aliases the class's public path to its shim.
It also sets optimizeDeps.include: ["openfl"] and defines global /
$_ globals that OpenFL's runtime expects.
License
MIT
