[英]How to restrict to make a build of react project if version is not changed/upgraded in package.json file
I want to enable production-level restriction in building to react application.我想在构建反应应用程序时启用生产级限制。 I want that if I do not change the version of react application it should give me an error during the build process with the error message "Change the react version in Package.json file".
我希望如果我不更改反应应用程序的版本,它应该在构建过程中给我一个错误消息“更改 Package.json 文件中的反应版本”。 How do I accomplish this strategy
我如何完成这个策略
Call the global process object's exit method调用全局进程对象的 退出方法
Node.js will normally exit with a 0 status code when no more async operations are pending.
当没有更多的异步操作挂起时,Node.js 通常会以 0 状态码退出。 The following status codes are used in other cases:
在其他情况下使用以下状态代码:
1 Uncaught Fatal Exception: There was an uncaught exception, and it was not handled by a domain or an 'uncaughtException' event handler.
1 未捕获的致命异常:存在未捕获的异常,并且未由域或“未捕获异常”事件处理程序处理。
For more information about exit codes you can take a look at process_exit_codes有关退出代码的更多信息,您可以查看process_exit_codes
Note: I did not tried to stop a build but you can try the following:注意:我没有尝试停止构建,但您可以尝试以下操作:
const REACT_VERSION = React.version; console.log(REACT_VERSION) if(REACT_VERSION <= "16.6.3"){ console.log("Change the react version in Package.json file, the current version is smaller than the lastes available.") process;exit(1); }
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.1/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.1/umd/react-dom.production.min.js"></script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.