Skip to content
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

Preamble for Customized Web Builders #3652

Open
pattobrien opened this issue Feb 24, 2024 · 2 comments
Open

Preamble for Customized Web Builders #3652

pattobrien opened this issue Feb 24, 2024 · 2 comments

Comments

@pattobrien
Copy link

pattobrien commented Feb 24, 2024

Context

i've been experimenting with the latest js_interop features, by building a node.js interop package (see: https://github.com/pattobrien/dart3_node_interop).

Since node.js is designed to run outside of the browser, there have been a number of unique aspects to compiling the js code from Dart source - notably, there's some code that must be initialized to add globals like require and process to the global scope. A node.js specific preamble can be found here.

Issue Description

It should be possible for devs to define some js code to be inserted along side the generated Dart code. This would make it a lot easier for developers to stay within the dart ecosystem, even when interop-ing with various configurations of js code.

Not being able to do so has caused interop package authors to fork the entire build_web_compilers package in order to work around the limitations and apply a few basic customizations. Such packages are:

I'm curious if such functionality already exists, or if it's something that would need to be added to the builders. As a side note, the build_web_compilers readme has not had content updated in about 6 years, and the Manual Usage section is especially out of date.

Additional Info

  • Dart SDK version: 3.3.0 (stable) (Tue Feb 13 10:25:19 2024 +0000) on "macos_arm64"
  • build_web_compilers v4.0.9
@jakemac53
Copy link
Contributor

This package does not support compiling to node. Ultimately, nobody on the team has any expertise in node or even uses it at all. So we can't reasonably support it.

Previously, there was a community build_node_compilers package but it looks to be quite out of date now.

If we could resolve this through some general mechanism to include a pre-amble as you suggest, that would be interesting though. I don't know exactly what it would look like, but if you wanted to work on a contribution we could review that.

@pattobrien
Copy link
Author

if you wanted to work on a contribution we could review that.

Absolutely! I'd love to take a swing at it.

I have a working Dart VSCode extension prototype, which runs in a Node runtime - so I can confirm its not only possible, but was generally surprised by how interoperable it is considering its a completely different environment. The implementation for preamble insertion is somewhat dependent on module-scoped exports, so I'm going to gather some feedback there and will open a PR once I have a good direction to propose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants