[Create React App] Explain eject, what does it mean? what are some examples

what does it mean npm run eject

fyi ive never done it, but I read that it un-abstracts a bunch of hidden stuff that react is using and makes the package.json file more detailed.

so whats the big deal? what does it mean that its a one-way operation and its permanent?

what are some examples of a two-way operation?

So if I do this and I dont like it, can’t I just checkout an earlier commit, and start over again? I dont understand this permanency

CRA is built on a load of JavaScript tools (Webpack, Babel, PostCSS and some others). Those tools can be used directly in JS programs, ie imported into and used to build other small programs (scripts).

When you install CRA, the CRA scripts use those tools directly to do what CRA does without you having to deal with the internals (such as, for example, configuring things). All the tools are bundled into one tool with it’s own API, which is what you work with in an un-ejected CRA app.

When you eject, the script that runs when you execute the command basically destroys the CRA scripts, splitting out their functionality so that you can access, [for example] things like the Webpack configuration.

It’s permanent because the scripts that were there and ran everything aren’t there anymore, you’re now working with the underlying tools.

Obviously, you can do that with any code in any language at any time if you’re using git. CRA has nothing to do with git though.

And anyway, say you eject then make some changes based on the the functionality exposed by ejecting CRA. If you reverted to the commit before ejecting, you don’t keep those changes, you’d just be going to a point in time before you made them. And even if you reverted and cherry picked out the code changes, they wouldn’t work, because they’re based on CRA being in an ejected state.

1 Like