Support node v13 with es modules#164
Conversation
|
One note of caution is that this is a breaking change: People who currently require or import ./dist/ paths directly would no longer be able to. This can be softened by adding an export of “./“. Excited to see this added to htm! |
| "import": "./dist/htm.mjs", | ||
| "require": "./dist/htm.js", | ||
| "browser": "./dist/htm.module.js", | ||
| "umd": "./dist/htm.umd.js" |
There was a problem hiding this comment.
Is this a good opportunity to consider dropping umd for the export map? Or perhaps in a separate PR.
I'm not sure I see the value in specifying a umd format output in export maps.
There was a problem hiding this comment.
I was just following the pattern from the main preact repo. I can do the change if needed.
There was a problem hiding this comment.
No worries, I think this is a good followup item to consider. Not blocking for this PR.
Thanks for doing the work!
|
Looks like the node version changed and the test is failing because npm cache has older version of compiled iltorb. Clearing the npm cache in Travis could help |
|
@vikerman - just switched to Actions, hopefully that addresses it. |
|
Everything looks good. I'm wondering if there's a way to test this though. {
"scripts": {
"test:dist": "npm pack && mv htm*.tgz test/fixtures/dist/htm.tgz && cd test/fixtures/dist && node ."
}
}... where // package.json
{ "dependencies": {"htm": "file:htm.tgz" } }// index.mjs
import 'htm';
import 'htm/preact';
import 'htm/preact/standalone';
import 'htm/react'; |
Creates conditional export that points "import" conditional exports to mjs files. This lets node load the esm version with having to set "type": "module" on the main package.json. This is similar to the approach in the main preact repo - preactjs/preact#2451
2adbe99 to
4603f22
Compare
|
Added the test. It's not hooked up to CI though. Would work for node versions >=13. [Edit: It's hooked up to the CI now] |
|
Hooked up the ESM dist test to CI when node version is 14.x. |
|
Wow, thanks @vikerman that is absolutely perfect! |
Creates conditional export that points "import" conditional exports to mjs files. This lets node load the esm version without having to set "type": "module" on the main package.json.
This is similar to the approach in the main preact repo - preactjs/preact#2451