Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ciscoheat/vite-plugin-haxe

Run Haxe code on Vite.
https://github.com/ciscoheat/vite-plugin-haxe

haxe vite vite-plugin

Last synced: 12 days ago
JSON representation

Run Haxe code on Vite.

Awesome Lists containing this project

README

        

# vite-plugin-haxe

Lets you run [Haxe](https://haxe.org/) code in your [Vite](https://vitejs.dev/) project. Supports client-side javascript currently.

## Installation & Configuration

Prerequisites: [Haxe](https://haxe.org/) and [Node.js](https://nodejs.org/).
`npm` is gladly substituted for [pnpm](https://pnpm.io/).

Open a terminal in your project folder and execute this:

```bash
npm create vite@latest my-haxe-app --template vanilla
cd my-haxe-app
npm install
npm install -D vite-plugin-haxe
```

Add a **vite.config.js**:

```js
import { defineConfig } from "vite";
import haxe from "vite-plugin-haxe";

/** @type {import('vite').UserConfig} */
export default defineConfig({
plugins: [haxe()],
});
```

Add/edit the following files:

**main.js**

```js
import "./style.css";
import "./main.hxml";
```

**main.hxml**

```bash
-cp src
-main Main
-dce full

# -js isn't needed, but helpful for IDE's.
-js main.js

-D source-map-content
-debug
```

**src/Main.hx**

```haxe
package;

import js.Browser.document;
import js.html.ButtonElement;

class Main {
static function main() {
document.getElementById('app')
.innerHTML = '








Vite + Haxe






Click on the Vite and Haxe logos to learn more



';

Counter.setupCounter(cast(document.querySelector('#counter'), ButtonElement));
}
}

class Counter {
public static function setupCounter(element:ButtonElement) {
var counter = 0;
final setCounter = (count:Int) -> {
counter = count;
element.innerHTML = 'count is $counter';
}
element.addEventListener('click', () -> setCounter(counter + 1));
setCounter(0);
}
}
```

Start the fun with `npm run dev`.