Skip to content

Add a way to generate JS libraries from Dart code #37617

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

Open
shinayser opened this issue Jul 24, 2019 · 5 comments
Open

Add a way to generate JS libraries from Dart code #37617

shinayser opened this issue Jul 24, 2019 · 5 comments
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. P4 web-js-interop Issues that impact all js interop

Comments

@shinayser
Copy link

shinayser commented Jul 24, 2019

This is a feature request.

Today Dart can be compiled to javascript via dart2js or via dartdevc but both does not provide a nice way to externalize the code for other developers to use, aka library.

Pehaps this could be an parameter addition to dartdevc, like dartdevc --library ... and then it generates the code in a externable format even easier to read, for humans .

That would complete even more tha Dart JS world and give it even more power due to the great rise of Node.Js nowadays.

@dgrove dgrove added the area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. label Jul 24, 2019
@vsmenon vsmenon added web-js-interop Issues that impact all js interop P4 labels Jul 25, 2019
@vsmenon
Copy link
Member

vsmenon commented Jul 25, 2019

This would be nice to have, but we have no near term plans for it.

@shinayser
Copy link
Author

I understand totally. Pehaps one day :)

@vsmenon
Copy link
Member

vsmenon commented Jul 25, 2019

I should point out that Sass is probably the best example of a Dart library that's callable from JS.

They do a fair bit of heavy-lifting themselves to setup entry points, package as a Node module, etc. E.g.,:

https://github.com/sass/dart-sass/blob/master/lib/src/node.dart#L41

@mraleph
Copy link
Member

mraleph commented Jun 16, 2021

note that @jakemac53 gave some very good arguments for why Dart might not be suitable for the task of creating libraries.

@sigmundch
Copy link
Member

@shinayser - thanks again for following up on this in #46378

As the others mentioned, this is a hard problem and unfortunately in tension with other project goals, so just for transparency, I want to be clear that I don't believe we'll be looking at this problem any time soon.

The one recommended way to use Dart from JavaScript applications is to explicitly export the APIs via JS-interop. Today, that entails adding a main method and use it to export individual APIs using allowInterop and external setters to expose static Dart functions to your JavaScript libraries. The Sass project @vsmenon mentioned above is a great example of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web-js Issues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop. P4 web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

5 participants