Get version number from package.json in React Redux (create-react-app)

后端 未结 4 1229
悲哀的现实
悲哀的现实 2021-02-01 11:34

OP EDIT: If anyone else comes across this: the app was created using create-react-app, which limits importing to within the src folder. However if you upgrade react-scri

4条回答
  •  终归单人心
    2021-02-01 12:19

    I don't think getting version by 'import' or 'require' package is correct. You can add a script in you package.json

    "start": "REACT_APP_VERSION=$npm_package_version react-app-script start",
    

    You can get it by "process.env.REACT_APP_VERSION" in any js files.

    It also works in build scripts, like this:

    "build": "REACT_APP_VERSION=$npm_package_version react-app-script build",
    

提交回复
热议问题