[英]How to do app versioning in create react app?
I need to display version of my react app in the footer in xyz format.我需要在页脚中以xyz格式显示我的 react 应用程序的版本。
I need this version to increment every time I deploy the app by being provided a choice if I want to increment x or y or z .如果我想增加x或y或z ,我需要在每次部署应用程序时增加这个版本。
How do I achieve this?我如何实现这一目标? :)
:)
To bump the version of your app you can use npm version .要提高应用程序的版本,您可以使用npm version 。
For example:例如:
npm version minor
You can use grunt-bump to handle your app versioning.您可以使用grunt-bump来处理您的应用程序版本控制。 As for displaying your app version, refer to Is there a way to get version from package.json in nodejs code?
至于显示您的应用程序版本,请参阅有没有办法在 nodejs 代码中从 package.json 获取版本? .
.
I don't think the answers from @Bertrand P or @VulfCompressor tell the complete picture.我认为@Bertrand P 或@VulfCompressor 的答案并不能说明全部情况。 I used genversion https://www.npmjs.com/package/genversion .
我使用了 genversion https://www.npmjs.com/package/genversion 。 The steps I did were:
我做的步骤是:
npm install genversion --save-dev
package.json
to genversion --es6 src/autobuild_version.js && react-scripts build
(I couldn't figure out a way to import the generated module from the lib
directory as suggested in the genversion documentation so I had to put it in the src
directory instead)package.json
的构建脚本修改为genversion --es6 src/autobuild_version.js && react-scripts build
(我想不出一种方法来从 genversion 文档中建议的lib
目录导入生成的模块,所以我有将其放在src
目录中)import { version } from './autobuild_version'
and use as appropriateimport { version } from './autobuild_version'
并根据需要使用src/autobuild_version.js
to .gitignore
(other source code control tools are available)src/autobuild_version.js
添加到.gitignore
(其他源代码控制工具可用)npm run build
Once you have a way to bump the version in package.json (eg npm version
, as suggested by @bertrand-p), you can then assign the version to an environment variable.一旦你有办法在 package.json 中修改版本(例如
npm version
,正如@bertrand-p 所建议的那样),你就可以将版本分配给一个环境变量。 For example, in .env
you can set:例如,在
.env
您可以设置:
REACT_APP_VERSION=$npm_package_version
Then you can access the variable from within your app via process.env.REACT_APP_VERSION
.然后您可以通过
process.env.REACT_APP_VERSION
从您的应用程序中访问该变量。
See also: https://github.com/facebook/create-react-app/issues/2466#issuecomment-357490359另见: https : //github.com/facebook/create-react-app/issues/2466#issuecomment-357490359
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.