npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@weahead/gatsby-plugin-api-extractor

v0.2.0

Published

Copies api folders from configured Gatsby plugins and manually specified dependencies to root.

Downloads

4

Readme

gatsby-plugin-api-extractor

This Gatsby plugin is design to copy all api folders of your configured Gatsby plugins and themes and merge them into an api folder in the root of the project.

It is meant for use with deployment tool ZEIT Now.

Usage

  1. Install the plugin:
npm i -SE @weahead/gatsby-plugin-api-extractor
  1. Add the plugin to gatsby-config.js:
module.exports = {
  plugins: [
    ...
    {
      resolve: '@weahead/gatsby-plugin-api-extrator',
      options: {
        prefix: '@weahead/api-prefix-',
        packages: [
          '@weahead/some-non-gatsby-theme-with-api-folder',
          '@weahead/other-non-gatsby-theme-with-api-folder',
        ]
      }
    },
    ...
  ]
}
  1. Build the project

  2. Deploy to ZEIT Now

Options

prefix (string): Only merges the directories of the Gatsby plugins that have a name that begins with this value. Think of it somewhat like a filter.

packages (string[]): If you have any dependencies that are NOT a Gatsby plugin or theme but that DOES have an api folder that should get merged add the package name to this array.

Motivation

ZEIT Now has a zero config approach to deploying apis.

A folder named api in the root of the project will have all its supported filetypes automatically compiled to a lambda and deployed alongside its other project files. Read more about this approach.

Distributing your Gatsby Themes isn't a big deal. However bundling the JavaScript files that make up the API for the theme inside the theme itself won't automatically deploy it to ZEIT Now. This plugin was created to help automate that.

This Gatsby plugin aims to help you distribute your Gatsby Themes including its own api folder and have all the api folders of all configured Gatsby plugins and themes merged into an api folder in the root of the project. This is done in Gatsbys onPostBuild lifecycle. This lifecycle is only called when gatsby builds and not during development mode. Read below for recommendatins for development environment.

Development environment

This plugin will do nothing when Gatsby is run in development mode (gatsby develop). As this plugin targets the ZEIT Now platform we recommend using now dev (build step | serverless functions) with a custom routes declaration in now.json that proxies all the requests to their respective lambda files.

In a monorepo it could look something like this:

{
  ...
  "routes": [
    {
      "src": "^/api/([^/]+)$",
      "dest": "packages/gatsby-theme-$1/api/index.js"
    },
    {
      "src": "^/api/([^/]+)/(.*)$",
      "dest": "packages/gatsby-theme-$1/api/$2.js"
    }
  ]
  ...
}

Running this with now dev would proxy requests:

http://localhost:3000/api/search => packages/gatsby-theme-search/api/index.js
http://localhost:3000/api/users/stats => packages/gatsby-theme-users/api/stats.js

License

X11