如何从类型脚本中的Package.json中获取版本? [英] How to get the version from the package.json in Typescript?
本文介绍了如何从类型脚本中的Package.json中获取版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已找到this Q&A。
我已尝试使用:
从Package.json中获取版本import { version } from './package.json';
但结果是:
package.json' has unsupported extension. The only supported extensions are '.ts',
'.tsx', '.d.ts'.
推荐答案
如果您处于普通JS环境中,为什么不直接使用
const pj = require('./package.json')
console.log(pj.version)
编辑
因为您似乎使用的是webpack,所以只需添加相应的加载器
module: {
loaders: [
...
{test: /.json$/, loader: 'json-loader'},
....
显然需要使用npm install
这篇关于如何从类型脚本中的Package.json中获取版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文