0

I have found out how to make React global using webpack: https://stackoverflow.com/a/32556581/565877

But I am wondering how to make it global for Parcel

Devin Rhode
  • 23,026
  • 8
  • 58
  • 72

1 Answers1

0

Based on some initial research, it looks like it's better to just accept having explicit imports. Less 'magic' means that when you want to refactor your code, it's easy to know if a module is still being used or not. Various bundlers can more quickly and easily understand the dependencies of various files.

I think it's more reasonable/forgivable to at least make React global, since it basically is in a React app in the first place. When you want to embed it in something that's non react, without compiling, then you can just add imports to every file then, probably with some simple scripting in the terminal.

Don't despair, since imports are so simple and basic (therefore annoying) they can be mostly automated by your editor/ide/editor plugins/etc.

One such tool that can help with this is: https://github.com/PavelDymkov/babel-plugin-auto-import

Here's a good editor plugin for vscode:

Auto Import - ES6, TS, JSX, TSX Sergey Korenuk | 46,224 installs | 71,453 downloads https://marketplace.visualstudio.com/items?itemName=NuclleaR.vscode-extension-auto-import (this is a fork of the more popular "Auto Imports" by soates, which only supports typescript)

Devin Rhode
  • 23,026
  • 8
  • 58
  • 72