If you want to use/show the version number in your angular app please do the following:
Prerequisites:
Steps:
- In your
/tsconfig.json
(sometimes also necessary in /src/tsconfig.app.json
) enable the resolveJsonModule option (webpack dev server restart required afterwards):
"compilerOptions": {
...
"resolveJsonModule": true
...
- Then in your component, for example
/src/app/app.component.ts
use the version info:
import { version } from '../../package.json';
...
export class AppComponent {
public version: string = version;
}
It's also possible to do step 2 in your environment.ts file, making the version info accessible from there.
Thx @Ionaru and @MarcoRinck for helping out.
This solution will not include the package.json contents, only the version number.
Tested w/Angular8/Node10/TypeScript3.4.3.
Please update your apps to use this solution cause depending on the contents of your package.json the original solution may implicate security issues.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…