1.0.3 • Published 4 years ago

gatsby-plugin-swarm v1.0.3

Weekly downloads
16
License
MIT
Repository
github
Last release
4 years ago

gatsby-plugin-swarm

Adds support for deploying Gatsby websites to Swarm and IPFS by ensuring that assets are relative.

This plugin is a modified version of gatsby-plugin-ipfs to add support for deploy on Swarm.

Installation

# Using npm
npm install --save gatsby-plugin-swarm

# Using yarn
yarn add gatsby-plugin-swarm

Usage

Set prefixPath to an arbitrary string (eg: __PATH_PREFIX__) and include the plugin in your gatsby-config.js file.

  • Also make sure the option prefix is equal to the pathPrefix.
  • The option pattern should match the swarm/ipfs path prefix.
module.exports = {
  pathPrefix: '__PATH_PREFIX__',
  plugins: [
    {
      resolve: `gatsby-plugin-swarm`,
      options: {
        prefix: `__PATH_PREFIX__`,
        pattern: /^(\/bzz:\/[^/]+)/ // use /^(\/(?:ipfs|ipns)\/[^/]+)/ for IPFS
      },
    },
  ],
};

To build with path prefix use the following command:

gatsby build --prefix-paths

Options

OptionExampleDescription
prefix"__PATH_PREFIX__"The name of the path prefix set in the gatsby-config.js file.
pattern/^(\/bzz:\/[^/]+)/The pattern of the Swarm/Ipfs subpath.
forceTrailingSlashtrueRedirect /<path>  to /<path>/ when trailing slash is missing. (optional)
useBasenametrueReplace the relative paths (../example) with the current Swarm/Ipfs path after page load. (/bzz:/hash/example). (optional)