简体   繁体   English

如果 package.json 文件中的版本未更改/升级,如何限制构建反应项目

[英]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.

相关问题 部署到 Heroku:如何在 NextJS 项目的 package.json 文件中更改构建脚本的文件路径 - Deploying to Heroku: How to change filepath for build script in package.json file for NextJS project 使用package.json构建一个js项目 - Build a js project with package.json 如何在package.json中的项目目录中为gulp文件创建路径 - How to make a path for gulp file in project's directory in package.json 如何在 package.json 中更改包的版本 - How to change the version of package in package.json 如何在package.json文件中指定项目npm注册表 - How to specify project npm registry inside package.json file 如何在package.json中运行nodejs项目 - How to run nodejs project in package.json 在 angular 项目 package.json 中添加 react 项目作为依赖 - Add react project as dependency in angular project package.json 创建 React App(npm run build) 生成包含不需要的 package.json 内容的 chunk.js 文件 - Create React App(npm run build) generates chunk.js file with unwanted content of package.json Angular / node.js 如何将应用程序版本从 package.json 复制到另一个非 json 文件 - Angular / node.js how to copy the app version from package.json to anothe non json file 如果第二个项目的package.json不在项目的根目录中,如何在package.json中添加github依赖关系 - How to add github dependency in package.json if package.json of second project not in the root of the project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM