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-pnpm

v1.2.10

Published

Easily add pnpm support to your Gatsby project

Downloads

22,357

Readme

PNPM Compatibility Plugin for Gatsby

codecov


Description

This plugin will configure Webpack module & loader resolution for packages installed via pnpm.

When using pnpm, building a Gatsby project will fail because pnpm uses a unique node_modules structure, and webpack doesn't know how to resolve packages in it. This plugin will configure webpack so that it is able to see Gatsby's dependencies.


How to install

  • Include the plugin in your gatsby-config.js.
// gatsby-config.js
module.exports = {
  plugins: [
    ...,
    `gatsby-plugin-pnpm`,
    ...
  ]
}

That's it. You should be able to build now.


Extended usage

Option: include - define custom resolutions

Variations:

  • Add resolution for specific package

    • Sometimes, Webpack may need to resolve a module that is a sub-dependency of one of your project's dependencies, and due to the way Webpack resolves modules (and sometimes because of the way those modules are written), it won't be able to. If this is the case, we need to point Webpack the way to where those sub-dependencies are located. To do that, please include your dependency in question in the include plugin option described below.

      • Note: if the strict option is true, then the package you define in this manner MUST be one of your project's direct dependencies, because it will be resolved using your project's node_modules directory.
  • add resolutions for directories

    • There are also times where you want Webpack to be able to resolve modules in a directory that is not a part of any of your dependencies node_modules. If that's the case, please include the directory path in the include option described below.

      • If you include a relative path, it will be resolved relative to your process.cwd().
      • MUST BE A DIRECTORY.

Option: projectPath - define your Project Root

  • This defaults to process.cwd().
  • You may encounter a time that your Project root is different than your process.cwd(). In that case, please define the projectPath option described below.
    • NOTE: If a relative path is defined, then it will be resolved relative to your process.cwd(), which may not be desired if you're using this option in the first place.

Option: strict - module resolution

  • This option defaults to true.
  • There may be times when you need to be able to resolve Gatsby, and whatever package names are defined in `include, using node's module resolution resolution.
    • true: Keep with the pnpm philosophy of scoping modules to your current project.
    • false: Use Node's module resolution. This causes node_modules to be checked walking backwards up your directory tree.

Available Options

| Option | Description | |:---------|:------------| | include | OPTIONAL: A list of package names and/or paths that you would like to be made available to Webpack. Each of these should either be the name of one of your project's direct dependencies, or a path to a folder containing packages that can be resolved as a module. | projectPath | OPTIONAL: The path to your project; i.e. the folder containing your package.json. This will be used when locating package names defined in include, and for resolving your project's node_modules directory | strict | OPTIONAL: Defaults to true. true = Resolve modules using the pnpm philosophy of limiting the module scope to your project. false = Use node's module resolution, which looks in every node_modules walking up your directory tree. |

Plugin options could be defined as follows:

// gatsby-config.js
const path = require('path');

module.exports = {
  plugins: [
    ...
    {
      resolve: `gatsby-plugin-pnpm`,
      options: {
        projectPath: path.dirname(__dirname), // use parent directory as project root
        include: [
          `my-awesome-package`, // <- resolve this package name
          `path/to/my/private/webpack/loaders` // <- resolve from this directory
        ],
        strict: true
      }
    }
  ]
  ...
}

Issues / Contributing

If you notice any issues caused by this plugin, or there seems to be some feature missing, please feel free to file an issue at https://github.com/Js-Brecht/gatsby-plugin-pnpm/issues