reactjs 这个“反应脚本弹出”命令有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48308936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 04:22:59  来源:igfitidea点击:

What does this "react-scripts eject" command do?

reactjswebpackcreate-react-appreact-scripts

提问by Ishan Patel

What does the npm run ejectcommand do? I do understand what other commands do like start, build, test. But no idea about eject.

什么是npm run eject命令吗?我确实了解其他命令的作用,例如启动、构建、测试。但不知道弹出。

回答by casieber

create-react-app encapsulates all of the npm modules it is using internally, so that your package.json will be very clean and simple without you having to worry about it.

create-react-app 封装了它在内部使用的所有 npm 模块,因此您的 package.json 将非常干净和简单,您无需担心。

However, if you want to start doing more complex things and installing modules that may interact with modules create-react-app is using under the hood, those new modules need to know what is available and not, meaning you need to have create-react-app un-abstract them.

然而,如果你想开始做更复杂的事情并安装可能与 create-react-app 在后台使用的模块交互的模块,这些新模块需要知道什么可用,什么不可用,这意味着你需要有 create-react -app 取消抽象它们。

That, in essence, is what react-scripts ejectdoes. It will stop hiding what it's got installed under the hood and instead eject those things into your project's package.json for everyone to see.

本质上,这就是react-scripts eject它的作用。它将停止隐藏它在引擎盖下安装的内容,而是将这些内容弹出到您项目的 package.json 中供所有人查看。

回答by Sergii

npm run eject

Note: this is a one-way operation. Once you eject, you can't go back!

注意:这是一种单向操作。一旦你eject,你不能回去!

If you aren't satisfied with the build tool and configuration choices, you can ejectat any time. This command will remove the single build dependency from your project.

如果您对构建工具和配置选择不满意,您可以eject随时进行。此命令将从您的项目中删除单个构建依赖项。

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except ejectwill still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.

相反,它会将所有配置文件和可传递依赖项(Webpack、Babel、ESLint 等)直接复制到您的项目中,以便您可以完全控制它们。除了所有命令eject仍然有效,但它们将指向复制的脚本,以便您可以调整它们。在这一点上,你是靠自己的。

You don't have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.

您不必永远使用eject. 精选功能集适用于中小型部署,您不应该觉得有义务使用此功能。但是我们知道,如果您在准备好时无法对其进行自定义,则此工具将没有用处。

link to documentation

文档链接



Alternatives to Ejecting

弹出的替代方法

Ejectinglets you customize anything, but from that point on you have to maintain the configuration and scripts yourself. This can be daunting if you have many similar projects. In such cases instead of ejecting we recommend to fork react-scriptsand any other packages you need. This articledives into how to do it in depth. You can find more discussion in this issue.

弹出让您可以自定义任何内容,但从那时起您必须自己维护配置和脚本。如果您有许多类似的项目,这可能会令人生畏。在这种情况下,我们建议您使用 forkreact-scripts和您需要的任何其他包,而不是弹出。本文深入探讨了如何做到这一点。您可以在此问题中找到更多讨论