Closed radex closed 6 years ago
it's because React Native needs CJS
React Native doesn't need CJS. ESM will work fine with React Native.
Do we really need ESM for tree shaking
Yup.
React Native doesn't need CJS. ESM will work fine with React Native
Hmm 🤔 What modern targets require CJS then? Is it just a Node.js thing? (🍉 doesn't have adapters anyway to make running on Node useful)
AFAIK all bundlers (Webpack, Parcel, Rollup) support ESM, so it must be just NodeJS. The only thing I can think of is running it in Node for testing, but then you could use @std/esm
or babel
for that. But probably who put it there will have more insight :D
Currently, we build and output Watermelon in two formats: ESM and CJS. If I understand correctly (@mobily knows this), it's because React Native needs CJS, but Webpack can do tree shaking with ESM. In #19, we add another format (same as source but with rewritten imports) to support Flow.
This complicates things because users have to include a Babel plugin to rewrite
@nozbe/watermelon/xxx
imports to@nozbe/watermelondb/{esm,cjs}/xxx
.import from '@nozbe/watermelondb/adapters'
) and are not exported from the main importclass
transpilation for React Native)