DEV Community

Masato Ohba
Masato Ohba

Posted on

Get dependencies written in package.json from JavaScript code

This is just a memo about how to refer dependencies written in package.json from JavaScript code.

import pkg from './package.json';

const dependencies = Object.keys(pkg.dependencies);
const devDependencies = Object.keys(pkg.devDependencies);
const peerDependencies = Object.keys(pkg.peerDependencies);
Enter fullscreen mode Exit fullscreen mode

It would be useful in case of specifying externals in rollup.config.js.

{
  external: Object.keys(pkg.dependencies)
  ...
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)