On your build pipeline, you could write a custom script that can extract necessary information from package.json and add it to new JSON file e.g. versionInfo.json.
Have the same file checked-in for local dev usage.
You can securely copy this and use this.
Doesn't work in Angular 12.
Error: Should not import the named export 'version' (imported as 'version') from default-exporting module (only default export is available soon)Try the following instead:
import pkg from 'path/to/package.json'Then when you reference it in your component, use the following:
version = pkg.version;This works, thanks.
However, with this approach you're copying the whole
package.jsonin build dest, which might be unsecure.Correct, there are security implications when importing the whole package.json.
Another option is to add node to your types property in tsconfig. Then you can use require like the following:
version = require('path/to/package.json').versionBut this also exposes
package.jsonto dist, right?On your build pipeline, you could write a custom script that can extract necessary information from
package.jsonand add it to new JSON file e.g.versionInfo.json.Have the same file checked-in for local dev usage.
You can securely copy this and use this.
Excuse me, but copy what? Did you paste a code snippet I can't see?