gatsby-source-npmjs

Source plugin for fetching files into the Gatsby graph from npmjs.com;

Install

npm install gatsby-source-npmjs

Usage

In your gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: require.resolve('gatsby-source-npmjs'),
      options: {
        name,
        patterns: [
          '**/blocklet.json',
          '**/blocklet.md',
          '**/logo.{jpeg,jpg,png,gif,svg}',
          '**/screenshots/*.{jpeg,jpg,png,gif,svg}',
          '**/package.json',
        ],
      },
    },
  ],
};

Query

You can query the nodes using GraphQL, like from the GraphiQL browser: localhost:8000/___graphql.

{
  query allFile {
    edges {
      node {
        id
        absolutePath
        relativePath
        internal {
          type
          mediaType
        }
        base
        publicURL
        npmMeta {
          repoName
          repoHref
        }
        childMarkdownRemark {
          htmlAst
        }
      }
    }
  }
}