Reputation: 12146
I have an SPA application (in React) built with Webpack (as part of create-react-app) where I display a version number retrieved from the package.json
likes this:
import npmInfo from 'package.json'
...
<div className="version">{npmInfo.version}</div>
However this results in also other package.json
being part of built javascript file and exposed to the public.
Is there an approach to retrieve just the version
from package.json
other than reading it in parent the process and setting it to environment variable (and reading it via process.env.VERSION
) ?
Upvotes: 1
Views: 625
Reputation: 1230
I'm not sure if this will solve your problem, as you are a bit against using (or rather setting?) environment variables, but if your application is ran or compiled by a npm script, you could use process.env.npm_package_version
.
Note: this will only be available if you use npm scripts.
Upvotes: 1