-
Notifications
You must be signed in to change notification settings - Fork 69
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
unpoly as ECMAScript module #136
Comments
Hi @JeremiePat, What kind of improvements do you feel this would bring? and are you familiar enough with CoffeeScript 1.x to know if this is easily achievable? I'm inclined to close this for now and possibly re-visit after v2 is released. WDYT? |
Can Coffescript transpile without resolving imports? (maybe transpiling a bundle per file?) In this case, you can import by path and the browser will understand it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules Paths must be resolvable by the browser ofc Not sure about any improvement it would bring though |
CoffeeScript is currently being removed file-by-file in This is done to make the project more accessible to contributors, and to ship separate ES5 and ESNext builds. Shipping a third ESM build is not super high on my long list of priorities now, as it offers no practical benefit to the |
Hi! To give some quick reason on the why ESM would be nice to me (I bet some people could have other reason for that)
|
Totally understand the desire for consistency (1). I'm also using ESM modules at work, but as a library maintainer I need to find the fewest number of builds that work for the largest number of people. Regarding (2), Unpoly sets a single property Regarding (3), Unpoly has never required a build step. In contrast, ESM modules force you to have a build step. At least until import maps have browser support. Even then funneling many small modules over HTTP may be too slow. |
I've come to this thread by way of this discussion: #252 And just want to add my +1 to seeing this issue addressed in due course. (For the record, I do import Unpoly and bundle it into a module. On the whole it's worked fine, and only recently, as indicated in that mentioned thread, have I run into "issues" with this approach.) I admire Unpoly's ability to get up and running with a simple In fact, unless I'm not thinking straight, there's no clean way to use Unpoly as a normal
That The choice would be to a) not build the app JS as an es6 module at all, or b) write separate JS either as a file or inline that includes any unpoly-related code. Neither of those are appealing. I want to embrace Unpoly as a part of the site, and leverage it in deep ways - for example, to use And ultimately I want to follow performance best practices, which includes efficient script loading. module/defer/async are important tools in that endeavor. I consider Unpoly to be the FAR superior choice among libraries offering HTML-over-the-wire functionality. But I would suggest that adoption will be hindered as long as it remains "officially" incompatible as an es6 module. (I'm sorry that I can't offer code contributions to this effort, my JS knowledge is just too weak!) |
We're conflating three different things in this thread. 1. Unpoly as an ES moduleThe original request by @JeremiePat was for a build that exports Unpoly's API as an ES6 module. In this model Unpoly would not define a import { layer } from 'unpoly'
layer.open() While I understand the desire for this, it's not super high on my personal list of priorities, as explained above. 2.
|
Apologies for hijacking @JeremiePat's original request. Hopefully it's nonetheless a productive discussion, but feel free to cut me off if I'm breaking protocols... Thanks @triskweline for this explainer. FWIW, AlpineJS faces a similar issue re: "knowing when to initialize", and addresses it by building to multiple targets (one for CDN, one for modules): https://github.com/alpinejs/alpine/blob/main/scripts/build.js The 2 build targets each have their own entry points, where the only difference is that the CDN target auto-initializes Alpine:
Whereas the module target does not:
Leaving it to the user to initialize as part of their module logic (as per https://alpinejs.dev/essentials/installation#as-a-module):
It's an elegant solution imo! It would be a breaking change to those of us importing Unpoly as a module, but seeing as that's not officially supported, it seems "acceptable". :) |
@johndwells Thank you for pointing out how Alpine solves this! It's always super insightful to see how other libraries approaches a problem. While this may end up the way we're solving this, I'm not quite ready to give up on a solution that does not require an additional build variant. We already have variants for ES5 and ES2020 and we will eventually have a variant for ES modules. Every time we add another axis to that matrix (like auto-loading or not) we multiply the number of builds. |
After some experimentation there may be a away to support loading via When I earlier said that there is no guarantee when
So if Unpoly would initialize on But didn't I also say that Unpoly initializes on We could probably get deferred initialization working by removing that optimization and always wait for |
Ah hah! So that's why my testing last night wasn't yielding expected results - because like you said, I understood |
There may even be a way to support
|
The upcoming version 2.3 will support loading with I'm leaving this issue open, as it was originally about a separate ESM build for Unpoly. |
@triskweline I've been watching your work on the other branch, thank you so much for giving these issues your time and care! |
You're welcome :) |
It would be a very nice improvement if unpoly could be available as a standard ECMAScript module in addition to the simple IIFE bundle.
This can be achieved independently than #124 but rewriting unpoly as a set of ES modules would be the nicest way to resolve both those issues.
The text was updated successfully, but these errors were encountered: