Tree-shaking optional require #19419
Replies: 2 comments
-
Hello, unfortunately we don't support it for |
Beta Was this translation helpful? Give feedback.
-
That's not trivial because the file importing OK, thank you! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For compatibility with different React versions, our library uses
Only
createRoot
andhydrateRoot
are used fromreact-dom/client
. Is there a way to tell that to Webpack? E.g. wouldconst { createRoot, hydrateRoot } = require('react-dom/client')
tree-shake it? I know about thewebpackExports
magic comment, but according to the documentation it seems to be unsupported forrequire
.I also have seen #16872, but we can't use top-level await and I am not sure this would work:
Another approach I thought of is separating into two files for React 18+ and React 16/17, since then we can just use non-dynamic
import
for both cases. But if I havereact18impl.ts
andreact16impl.ts
with the same exports, how do I properly re-export them so files which import them don't need to care about the React version?in a
.cts
file maybe?Beta Was this translation helpful? Give feedback.
All reactions