-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support requiring modules via JS module systems #25059
Comments
I'm renaming this, since a number of broader issues have been merged into it and the old name was pretty narrowly-scoped. |
#29808 has good discussion on this. |
Related issue, but this one is about how we export a module for JS consumption, rather than import: #27692 |
Has there been any progress here? Been building a commercial app on angulardart, but losing many high quality js modules feels like a dealbreaker...I can’t figure out a reasonable workaround for necessary webgl libraries :/ |
Here's some JS interop examples: https://github.com/matanlurey/dart_js_interop#dart_js_interop Could you explain more what you're trying to do with webgl? Are there any particular libraries you're trying to use? |
For sure - I'm using 2dimensions' Flutter runtime for a mobile app, and I want to use their webGL runtime in AngularDart to maximize code+asset reuse. See https://github.com/2d-inc/Nima-WebGL That lib is littered with import/exports, including imports of external params from gl-matrix. My understanding was that interop couldn't currently handle this structure, and that I'd need to refactor all that code to make it play nice...buuut I could be missing something, since I'm pretty new at all this :) |
You should be able to load that JS library as normal -- any imports/exports inside of JS code are fine. I believe Then to use that library from Dart, you'd want to write a .dart file that contains the interfaces: @JS('Nima')
library nima_webgl;
// note: Dispatcher class needs to be defined too
// it would be nice to add type annotations, especially for return types
@JS()
class Actor extends Dispatcher {
external factory Actor();
external addDependency(a, b);
external sortDependencies();
external addDirt(component, value, recurse);
external update();
external get root;
external resolveHierarchy(graphics);
external dispose(graphics);
external initialize(graphics);
external advance(seconds);
external draw(graphics);
external getNode(name);
external getAnimation(name);
external getAnimationInstance(name);
external makeInstance();
external computeAABB();
external copy(actor);
} Similar thing for any other public classes. That makes Dart aware of the JS classes, so you can use them. |
@jmesserly Hey. |
I don't know how to use webpack, sorry! They do have documentation: https://webpack.js.org/concepts/, maybe that will help get you started. |
@jmesserly Have you ever tried to use one of the top JS libs in Dart? That's one of Dart's weakest points... |
Yeah, totally. It's less than ideal (to put it mildly). I'm working on making that better. I would like to spend some time thinking about integration with JS module bundlers and build systems too (to address @Aetet's point above). But first, I want to address the core features of interoperability: being able to nicely express and use JS APIs in Dart and vice versa. |
While it's possible to work around this by treating |
This is becoming more of an issue as browsers have implemented modules and more browser libraries are moving to modules instead of globals. More and more library authors are no longer shipping global builds of their libraries. Along with node's new .mjs file format, this is no longer a fringe case. |
@knownasilya did you have success with a webpacked library?
tried this: with no success, Dart do not see my EDIT: ok I think I got it |
I'm trying to interop a modern javascript library with modules.
It is a big library with like 20 modules
On the javascript site, they don't put those modules in the html, but use browsify or webpack.
I have no clue how to write an interop for that.
http://prosemirror.net/doc/manual.html#bundling
The text was updated successfully, but these errors were encountered: