-
Notifications
You must be signed in to change notification settings - Fork 6
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
Modularize makeESModule #2
Comments
Hi @hmsk , thanks for opening this issue. :-) Just to be clear I correctly understand what you want this function to do:
|
Thanks for replying! Correct! I'm intending to pass the output string from node-elm-compiler and expect it's ESM-ized. The exact case is a plugin for vite. To bundle compiled |
Ah cool, I was suspecting it had to be for some kind of plugin. I've knows snowpack but I haven;t heard about Vite before you mentioned it. Good to know. :-) I think the function that you want already exists, it just isn't exposed yet. Should be easy do if you need it as a NodeJS export. If you need it as an ES6 export I think I may have to do some extra work. |
Ah from your first comment it looks like you want the function as a ES Module and not CommonJS. I am not 100% sure how that works. I am thinking about providing both the CommonJS and ES Module export as separate module and declare them in the package.json like this: {
"main": "./common-js-export.js",
"module": "./es-module-export.js"
} Do you think that would work? Or maybe it would be best to add something like rollup which generates the correct outputs. |
Tried to read a bit about how to use ES6 Modules with Node. The docs are a mess and the support is still experimental https://nodejs.org/api/packages.html#packages_dual_commonjs_es_module_packages |
Ah, my sample code was intending on TypeScript, that means CJS vs ESM doesn't matter for me and I just expected it's a named export then. At least I'm not going to use the function in ES env actually. So not pure ESM is required. To make changes on your repo minimum, how's about separating the function into another file and export through CJS style |
Ah great, if CJS is good enough for you then this is an easy thing to do. Will start implementing now. 👍 |
Allright it's published. https://github.com/ChristophP/elm-esm#nodejs-usage Let me know if this works for you. |
That's perfect, my small wrapping for IIFE is completely naturalized by esm-elm 🎉 🎉 Thanks for your generous and immediate implementation! |
Awesome glad this is already put to use. 👍 |
Thanks for sharing such a useful implementation ✨
One thing I'd like to request is that the distributed
elm-esm
npm provides importablemakeESModule
.I'm imagining an interface like:
I could build my own function by copying your code actually. However, I'm wondering if
elm-esm
becomes a single source of truth for this purpose in the community, and we can contribute when Elm core changes outcome in the future.The text was updated successfully, but these errors were encountered: