Overview
This document provides a guide for installing and running IPFS and OrbitDB with SvelteKit, including steps to reproduce the setup. It also mentions the need to install certain dependencies and provides instructions for building the required modules for the browser.
Features
- Integration of IPFS and OrbitDB with SvelteKit
- Use of esbuild for building IPFS-core for the browser
- Installation of necessary dependencies like ipfs-core, process, and util
- Configuration of SvelteKit to work with IPFS and OrbitDB
- DAG building using ipfs.dag.put()
Installation
- Clone the SvelteKit directory.
- Install SvelteKit using the command
npm install. - Install ipfs-core by running
npm i ipfs-core. - Install process and util dependencies, which are not available in the browser, using the command
npm i process util. - Create a file named
src/node-globals.jsand save the required globals in it. - Install esbuild as a development dependency using
npm i -D esbuild. - Add a script to the package.json file to run the esbuild build process.
- Run the esbuild script using
npm run esbuild. - Import IPFS in your app by adding the following code inside the onMount hook in Svelte:
import IPFS from 'src/modules/ipfs-core/ipfs-core.js'. - Run the app using the command
npm run dev. - Build the app using
npm run build. - Install the adapter for static sites using
npm i @sveltejs/adapter-static. - Add the following lines to your svelte.config.js file:
import adapter from '@sveltejs/adapter-static';
export default {
...
kit: {
...
adapter: adapter({ fallback: 'index.html' }),
...
},
...
};
- Build the app again using
npm run build. - Preview the built app using
npx serve __sapper__/build. - Open the app in your localhost.
Note: In development mode, SvelteKit replaces globalThis.process.env.NODE_ENV with globalThis."development", which can cause issues. To prevent this, replace globalThis.process.env.NODE_ENV accordingly during the esbuild process.
Summary
This guide provides step-by-step instructions for installing and running IPFS and OrbitDB with SvelteKit. It covers the installation of dependencies, building IPFS-core for the browser, and configuring SvelteKit to work with IPFS and OrbitDB. The guide also includes instructions for running and building the app, as well as a note about preventing issues during development mode.