read-pkg-json: 方便读取 package.json 的工具
方便在 cjs/esm 环境中读取 package.json 的工具
🕐
安装
yarn add @jswork/read-pkg-json使用
import readPkgJson from '@jswork/read-pkg-json';
// 1. current dir
const pkg = readPkgJson();
// 2. specify dir
const pkg = readPkgJson('path/to/your/project');原理
const res = fs.readFileSync('path' + 'package.json', 'utf-8');
return JSON.parse(res)其它
| module type | 代码 |
|---|---|
| cjs(默认不写) | |
| esm(module) | |