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

gatsby-plugin-babel-plugin-typescript-to-proptypes

v1.0.5

Published

A gatsby plugin that wraps [babel-plugin-typescript-to-proptypes](https://www.npmjs.com/package/babel-plugin-typescript-to-proptypes)

Downloads

195

Readme

Description

As the name suggests, this plugin is a pretty basic wrapper around babel-plugin-typescript-to-proptypes.

Dependencies

How to install

To get started, install this plugin and babel-plugin-typescript-to-proptypes:

When using NPM:

npm i -D gatsby-plugin-babel-plugin-typescript-to-proptypes babel-plugin-typescript-to-proptypes

When using Yarn:

yarn add --dev gatsby-plugin-babel-plugin-typescript-to-proptypes babel-plugin-typescript-to-proptypes

We need to install both as babel-plugin-typescript-to-proptypes is a peer dependency of this plugin.

Available options

All the options of babel-plugin-typescript-to-proptypes are available and will be passed through.
Please see the docs of that plugin on the available options.

The additional disable option has been added for convenience sake, which will disable this plugin from running altogether.

When do I use this plugin?

Use this plugin if you want propTypes to be added to your components based on your type definitions.
If you're not using Gatsby with Typescript, this plugin is not for you.
Again, more to be found on that in the docs on babel-plugin-typescript-to-proptypes

Example usage

//gatsby-config.js
{
    resolve: "gatsby-plugin-babel-plugin-typescript-to-proptypes",
    options: {
        ... Any options from `babel-plugin-typescript-to-proptypes` you want to provide
    }
}

Once you've configured this plugin, you're free to delete any propTypes that you might already have defined in your code.

You might want to set the disable option depending on the environment you're running gatsby in, as most people don't need propTypes in production builds.
Gatsby will set the env variable NODE_ENV to development or production for the gatsby develop and gatsby build commands respectively, which means a good way to configure the disable option would be as follows:

//gatsby-config.js
{
    resolve: "gatsby-plugin-babel-plugin-typescript-to-proptypes",
    options: {
        disable: process.env.NODE_ENV === "production",
        ... //Any other options you want to provide
    }
}

Do I really need a plugin for a plugin?

No, if you'd rather have control over adding babel-plugin-typescript-to-proptypes yourself, you could also implement things yourself in gatsby-node.js. In that case you don't need this plugin.
This plugin was made because it was needed for a personal project, but I thought I'd provide the functionality to other people who went looking for the same thing as me.

E.g.

exports.onCreateBabelConfig = ({stage, actions: {setBabelPlugin}}, options) => {
  if (stage === "develop") { //Gatsby calls `onCreateBabelConfig` on every stage for both `gatsby build` and `gatsby develop` so we only need one stage
    setBabelPlugin({
      name: require.resolve("babel-plugin-typescript-to-proptypes"),
      options
    });
  }
};

See the Gatsby Node API docs for more info.

How to develop locally

  • Clone this plugin
  • That's it, this plugin has no dependencies apart from having node installed on your system

Contributing

Please file an issue in this repo and/or open a PR if you'd like to contribute