Skip to content

Instantly share code, notes, and snippets.

@bartosjiri
Last active September 1, 2020 19:24
Show Gist options
  • Save bartosjiri/e5bc96ba9c0959c9a417eeb541bde8fd to your computer and use it in GitHub Desktop.
Save bartosjiri/e5bc96ba9c0959c9a417eeb541bde8fd to your computer and use it in GitHub Desktop.
Import a local plugin into a Gatsby project

Importing a local plugin into Gatsby

Instructions

  1. Include the plugin in plugins folder by following the official documentation.
  2. Update webpack config in the gatsby-node.js file:
    const path = require('path')
    
    exports.onCreateWebpackConfig = ({actions}) => {
      actions.setWebpackConfig({
        resolve: {
          alias: {
            '~plugins': path.resolve(__dirname, 'plugins')
          }
        }
      })
    }
    
  3. Import the plugin into any component:
    import {ComponentName} from '~plugins/gatsby-plugin-name'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment