flyover / imgui-js

JavaScript bindings for Dear ImGui using Emscripten and TypeScript
https://flyover.github.io/imgui-js/example/
MIT License
951 stars 99 forks source link

SystemJS replaced with CJS, added ES build #30

Closed vojty closed 3 years ago

vojty commented 3 years ago

Hello, I tried to use this package with webpack and ended up with this.

Here is what I changed:

  1. Moved TS files to src directory
  2. Removed all generated JS files from repository (except dist directory)
  3. Renamed example/imgui_impl to src/imgui_impl_webgl since it's something you kinda need to use in the browser.
  4. Switched module system from SystemJS to CJS. Example is using just one generated file main.js now.
  5. Added ES build that can be used with webpack or in modern browsers.

Example usage

import * as ImGui from "imgui-js";
import * as ImGui_Impl from "imgui-js/es/imgui_impl_webgl";

// there should be probably just one entry point eg. import { ImGui, ImGui_Impl, MemoryEditor } from 'imgui-js'
...

I know this might be a little bit controversial change, but I believe the most of the users just want to simply type yarn add imgui-js (without any compiling & building) and let them decided, what module system they want to use.

It would be nice to publish this as an NPM package eventually.

I see that the codepen examples are using SystemJS too, I'll be happy to convert them as well. Please let me know what do you think and if it's the way you want to go or not. Thanks

flyover commented 3 years ago

Hey Tomáš, thanks for putting this pull request together. I had been working on something similar to this, but I wasn't sure I had the correct rollup settings. I've checked in what I have so far and updated the CodePen examples. You now only need to include the UMD and initialize the WebAssembly module using:

await ImGui.default();
vojty commented 3 years ago

I'm not sure, what has just happened in master branch :) The point of this PR was to provide en ES build (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), so you could use it with import/export (which is quite common these days) and have type declaration files too. You can keep UMD build as well, so anybody can easily play with it just by linking the url, that's fine. The files in the build directory are "polluted" by SystemJS and the imgui_impl is missing (which seems to me to be quite necessary)

vojty commented 3 years ago

obsolete -> closing

@flyover I'm sure you are busy, but are you interested in something like this in the future or not? I don't really want to maintain a fork just for the different build system...