Skip to content

Commit 4eacad2

Browse files
GeTechGjoshtynjala
authored andcommitted
feat(rollup-genes-sample): add new sample demonstrating Rollup and Genes integration
1 parent b27bd8f commit 4eacad2

File tree

7 files changed

+205
-0
lines changed

7 files changed

+205
-0
lines changed

samples/rollup_genes/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Use Rollup with OpenFL Loader for Vite
2+
3+
This sample demonstrates how [vite-plugin-openfl](https://github.com/feathersui/vite-plugin-openfl) may be used with [Rollup](https://rollupjs.org/) instead of Vite.
4+
5+
## Instructions
6+
7+
To build a production JavaScript bundle, run the following command:
8+
9+
```sh
10+
npm run build
11+
```
12+
13+
## Links
14+
15+
- [vite-plugin-openfl](https://github.com/feathersui/vite-plugin-openfl)
16+
- [OpenFL](https://openfl.org)
17+
- [Rollup](https://rollupjs.org/)

samples/rollup_genes/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "vite-plugin-openfl-rollup-sample",
3+
"version": "2.0.0",
4+
"description": "Sample that demonstrates how to use vite-plugin-openfl with Rollup",
5+
"repository": "https://github.com/feathersui/vite-plugin-openfl.git",
6+
"devDependencies": {
7+
"rollup": "^4.53.3",
8+
"rollup-plugin-copy": "^3.5.0",
9+
"vite-plugin-openfl": "^2.0.2"
10+
},
11+
"scripts": {
12+
"build": "rollup -c"
13+
}
14+
}

samples/rollup_genes/project.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<project>
3+
<meta title="OpenFL Plugin for Vite with Rollup + Genes"/>
4+
<meta package="com.feathersui.vite.rollup"/>
5+
<meta version="1.0.0"/>
6+
<meta company="Bowler Hat LLC"/>
7+
<app main="Main"/>
8+
<!--
9+
the output file name is referenced when calling lime.embed() in index.html
10+
-->
11+
<app file="ViteRollupSample"/>
12+
13+
<window allow-high-dpi="true"/>
14+
<window fps="60"/>
15+
<window fps="0" if="html5"/>
16+
17+
<source path="src"/>
18+
19+
<haxelib name="openfl"/>
20+
<haxelib name="genes"/>
21+
</project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<title>OpenFL with Rollup</title>
6+
7+
<meta
8+
id="viewport"
9+
name="viewport"
10+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
11+
/>
12+
<meta name="apple-mobile-web-app-capable" content="yes" />
13+
14+
<script>
15+
window.addEventListener(
16+
"touchmove",
17+
function (event) {
18+
event.preventDefault();
19+
},
20+
{ capture: false, passive: false }
21+
);
22+
if (
23+
typeof window.devicePixelRatio != "undefined" &&
24+
window.devicePixelRatio > 2
25+
) {
26+
var meta = document.getElementById("viewport");
27+
meta.setAttribute(
28+
"content",
29+
"width=device-width, initial-scale=" +
30+
2 / window.devicePixelRatio +
31+
", user-scalable=no"
32+
);
33+
}
34+
</script>
35+
36+
<style>
37+
html,
38+
body {
39+
margin: 0;
40+
padding: 0;
41+
height: 100%;
42+
overflow: hidden;
43+
}
44+
45+
#openfl-content {
46+
width: 100%;
47+
height: 100%;
48+
}
49+
</style>
50+
</head>
51+
52+
<body>
53+
<noscript
54+
>This webpage makes extensive use of JavaScript. Please enable JavaScript
55+
in your web browser to view this page.</noscript
56+
>
57+
58+
<div id="openfl-content"></div>
59+
60+
<script type="module">
61+
import "./project.js";
62+
/*
63+
the first argument passed to lime.embed() is the <app file="******"/>
64+
value from project.xml
65+
*/
66+
lime.embed("ViteRollupSample", "openfl-content", 0, 0, {
67+
parameters: {},
68+
});
69+
</script>
70+
</body>
71+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import openfl from "vite-plugin-openfl";
2+
import copy from "rollup-plugin-copy";
3+
import { defineConfig } from "rollup";
4+
5+
export default defineConfig({
6+
context: "window",
7+
input: "project.xml",
8+
output: {
9+
dir: "dist",
10+
format: "es",
11+
},
12+
preserveEntrySignatures: false,
13+
plugins: [
14+
openfl(),
15+
copy({
16+
targets: [{ src: "public/**/*", dest: "dist" }],
17+
}),
18+
],
19+
});

samples/rollup_genes/src/Main.hx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import com.example.MyModule;
2+
import genes.Genes;
3+
import openfl.display.Sprite;
4+
import openfl.events.MouseEvent;
5+
import openfl.text.TextField;
6+
import openfl.text.TextFormat;
7+
8+
class Main extends Sprite {
9+
private var button:Sprite;
10+
11+
public function new() {
12+
super();
13+
14+
button = new Sprite();
15+
button.buttonMode = true;
16+
button.mouseChildren = false;
17+
button.graphics.beginFill(0xff0000);
18+
button.graphics.drawRoundRect(0.0, 0.0, 150.0, 50.0, 10.0);
19+
button.graphics.endFill();
20+
var buttonText = new TextField();
21+
buttonText.defaultTextFormat = new TextFormat("_sans", 20, 0xffffff);
22+
buttonText.autoSize = LEFT;
23+
buttonText.text = "Click Me";
24+
buttonText.x = (button.width - buttonText.width) / 2.0;
25+
buttonText.y = (button.height - buttonText.height) / 2.0;
26+
button.x = 10.0;
27+
button.y = 10.0;
28+
button.addChild(buttonText);
29+
addChild(button);
30+
31+
button.addEventListener(MouseEvent.CLICK, onButtonClick);
32+
}
33+
34+
private function onButtonClick(event:MouseEvent):Void {
35+
button.mouseEnabled = false;
36+
button.alpha = 0.5;
37+
38+
// load the module on demand
39+
Genes.dynamicImport(MyModule -> new MyModule()).then((module) -> {
40+
module.x = 10.0;
41+
module.y = 70.0;
42+
addChild(module);
43+
});
44+
}
45+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.example;
2+
3+
import openfl.text.TextFormat;
4+
import openfl.text.TextField;
5+
import openfl.display.Sprite;
6+
7+
// as long as it is referenced only in a Genes.dynamicImport() call, this class
8+
// will be loaded on-demand, instead of being included in the main bundle
9+
class MyModule extends Sprite {
10+
public function new() {
11+
super();
12+
var tf = new TextField();
13+
tf.defaultTextFormat = new TextFormat("_sans", 20, 0x333333);
14+
tf.autoSize = LEFT;
15+
tf.text = "Hello, I'm a Genes module!";
16+
addChild(tf);
17+
}
18+
}

0 commit comments

Comments
 (0)