-
Notifications
You must be signed in to change notification settings - Fork 781
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
Separate/more granular dist targets #951
Comments
Node now supports ES modules. |
What about doing as you say for module and unpkg, and continue with IIFE for "main"? |
True, but only as of 14.x, and even then it's considered experimental/unstable (albeit, enabled by default). Lots of folks are still on 12.x, which is the latest LTS release, or even 10.x.
Sure, but what's your concern about using UMD? It still falls back to IIFE for the browser and enables older versions of Node to use the library. I think it's legitimate to say "we just aren't going to support CommonJS." I did some research and it appears that supporting both CommonJS and ES modules can lead to some subtle problems in Node, which can be avoided/mitigated but would require some commitment (see the link). If we make a policy of not supporting CommonJS, then we should be explicit about it and make the following changes:
That said, I do want to emphasize that ES modules support is still experimental in Node 14, even if it's enabled by default. The "proper" way, I think, is to handle both CJS and ESM, but it might not be necessary. |
Assuming that Hyperapp's modules are stateless and will remain stateless, IMHO the most comprehensive configuration would look like:
|
I agree with all the points you listed in #951 (comment) and that's exactly my plan in time for the official V2 release, you just clarified a bunch of stuff, thanks.
Sure thing, we'll do by then.
That's my plan. |
Sounds good :-). I'll close this issue then. |
@earksiinni Is there any difference between "main" and "module" if both point to an ES module? I mean this: "main": "src/index.js"
"unpkg": "dist/index.min.js"
"type": "module" instead of "main": "src/index.js"
"module": "src/index.js"
"unpkg": "dist/index.min.js"
"type": "module" |
You're right! To my knowledge, there's no difference if both point to an ES module. Omitting |
@earksiinni Maybe I found it unpkg/unpkg#93 (comment) |
Ah sorry, I forgot to reply @jorgebucaran. It's specified on unpkg's main page:
|
when creating mjs modules please take into account that either otherwise node will import modules as commonjs files and complain about the import or export statements. this is true even if package.json of the parent project includes rollup and the other transpilers handle this as one would expect and without errors, node does not. running into the same issue in the newest version of hyperapp-render: issue |
Thanks for all the info @jaeh! 👍 |
It's really convenient to directly import Hyperapp via Unpkg from inside a
<script type="module">
tag. At present, however, importing directly from Unpkg pulls insrc/index.js
, which isn't minified. This behavior is a problem because we don't get the chance to minify using a bundler when importing directly within a script tag.Furthermore,
dist/index.js
is currently built using IIFE, whereas UMD would be much more flexible (e.g., if you want to import Hyperapp in a Node environment).I propose that package.json point to three targets:
"main": "dist/index.js"
: UMD target. This file is currently built using IIFE, whereas switching to UMD will allow the file to be imported as a CommonJS/AMD and falls back to IIFE in a browser environment. UMD may increase the bundle size vs. pure IIFE, however."module": "src/index.js"
: ES modules target."unpkg": "dist/index.es.min.js"
: Minified ES modules target.The text was updated successfully, but these errors were encountered: