简体   繁体   English

React 如何处理应用程序版本控制和版权年份?

[英]React how to handle app versioning and copyright year?

I have a react app built with Nrwl that has a footer.我有一个用 Nrwl 构建的带有页脚的反应应用程序。 In the footer I have the copyright and the version number.在页脚中,我有版权和版本号。 What is the best way to dynamically set those?动态设置它们的最佳方法是什么?

  1. I can get the current year easily.我可以轻松获得当前年份。 But I am concerned with the device datetime.但我担心设备的日期时间。
  2. The version number.版本号。 Should I set statically or read from JSON file?我应该静态设置还是从 JSON 文件中读取?

How do you tackle this?你如何解决这个问题?

Short Answer:简短的回答:

  1. Yes, you can fetch Date from a free API like ( http://worldtimeapi.org/ ) giving a Date object on the time zone or area provided.是的,您可以从免费的 API 中获取日期,例如( http://worldtimeapi.org/ )在提供的时区或区域上给出日期 object。
  2. The version number must be inferred from package.json to maintain versioning.版本号必须从package.json推断出来以维护版本控制。

Long Answer:长答案:

  1. You can hit the below API with the physical location of the business or brand.您可以点击下面的 API 与企业或品牌的实际位置。 So you will get the time for the actual location where your business reside.因此,您将获得您企业所在实际位置的时间。

http://worldtimeapi.org/api/timezone/Europe/Dublin

This will give a you a response like following, you can easily get year and further in this.这会给你一个像下面这样的回应,你可以很容易地得到一年甚至更远。

{"abbreviation":"GMT","client_ip":"39.42.97.186","datetime":"2021-02-01T11:09:53.942753+00:00","day_of_week":1,"day_of_year":32,"dst":false,"dst_from":null,"dst_offset":-3600,"dst_until":null,"raw_offset":3600,"timezone":"Europe/Dublin","unixtime":1612177793,"utc_datetime":"2021-02-01T11:09:53.942753+00:00","utc_offset":"+00:00","week_number":5}
  1. You can add a global variable in your webpack config as mentioned following, that gives you the package version value in your application.您可以在 webpack 配置中添加一个全局变量,如下所述,它会在您的应用程序中为您提供 package 版本值。
const PACKAGE = require('./package.json');

module.exports = {
  // Other stuff
  plugins: [
    new DefinePlugin({
      APP_VERSION: PACKAGE.version 
    });
  ]
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM