angular - 如何从角度库中的 package.json 获取版本
问题描述
我不能package.json
在 Angular 的库中包含版本,但它可以在项目中使用。我像这样使用导入:
import { version } from '../../package.json';
并得到以下错误:
ERROR: error TS6059: File '/Users/.../library/package.json' is not under 'rootDir' '/Users/.../library/src'. 'rootDir' is expected to contain all source files.
An unhandled exception occurred: error TS6059: File '/Users/.../library/package.json' is not under 'rootDir' '/Users/.../library/src'. 'rootDir' is expected to contain all source files.
See "/private/var/folders/tw/z8v0wkt50g5876740n99hzy00000gp/T/ng-0JDpjC/angular-errors.log" for further details.
穿越的方式require
包括了package.json
会带来安全风险的整体。import { version } from '../../package.json'
仅包括版本号,但适用于 Angular 应用程序而不是库。
解决方案
您可以像常规模块一样导入它:
import { version } from 'package.json'
但请务必添加"resolveJsonModule": true
到compilerOptions
您的 tsconfig.json 中。
推荐阅读
- html - 网格未在移动设备上堆叠
- python - Python:有没有办法改变 tkinter 窗口的形状?
- c# - ConfigurationManager:总是键值对?
- php - 在 WooCommerce 中将折扣运费与折扣购物车商品价格相结合
- python - 可以使用 SymPy 求解具有可变系数的一阶方程吗?
- vim - "vim ~/.zshrc" 用于安装 Flutter SDK
- excel - 根据表中的值返回列标题
- c# - C# 如何检索 Dynamics Finance and Operations 实体记录
- c - C 中的 readinf 文件,直到出现 int
- vue.js - 在使用 CDN 中的 Vuejs 并运行 Codekit 时,如何将组件拆分为更小的文件?