mdx-embed icon indicating copy to clipboard operation
mdx-embed copied to clipboard

chore/babel-esm

Open PaulieScanlon opened this issue 3 years ago • 4 comments

  • change babel config to export ESM

@spences10 If you happen to speak to Chris again i think this is what we'll need but i've gotta be honest i've run out talent with Babel.

Before this PR i was transforming syntax to cjs, and now i've removed @babel/plugin-transform-modules-commonjs and set @babel/preset-env to "modules": false which i think now will export just the ES syntax.

If you give this a pull and run yarn build and have a look at the dist folder the exported code looks much more like the kinda thing we'd write.

Also made a small change to tsconfig as i was exporting the types to a types dir but wasn't point the declarationDir at that dir so we would have proabably had a "types not found" error if we'd tried to use the package in a TypeScirpt project.

PaulieScanlon avatar Sep 10 '20 08:09 PaulieScanlon

I think that's it mate, Chris said that we'd need to ship an ESM build to do that configure TS to pass through ESM, compile the JSX and remove the Type annotations then output the ESM to module.

Chris also referenced the keys options in microbundle for how to export: https://www.npmjs.com/package/microbundle

And the TS Handbook, but I can't find specifically where he was referencing, sorry: https://www.typescriptlang.org/docs/handbook/modules.html

spences10 avatar Sep 10 '20 10:09 spences10

Found it!

--esModuleInterop

spences10 avatar Sep 10 '20 10:09 spences10

@spences10 i have that already in the tsconfig i'm assuming it has to be true right?

PaulieScanlon avatar Sep 10 '20 11:09 PaulieScanlon

@spences10 lets shelve this for the moment. With export to ES Modules rather than Common Js both the Next demos break. I don't know enough about this to know what needs to be changed.

PaulieScanlon avatar Sep 15 '20 19:09 PaulieScanlon