Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

wip: example with rollup #7

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions examples/browser-rollup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<p align="center">
<a href="https://js.ipfs.io" title="JS IPFS">
<img src="https://ipfs.io/ipfs/Qme6KJdKcp85TYbLxuLV7oQzMiLremD7HMoXLZEmgo6Rnh/js-ipfs-sticker.png" alt="IPFS in JavaScript logo" width="244" />
</a>
</p>

<h3 align="center"><b>js-ipfs with rollup</b></h3>

<p align="center">
<b><i>Bundle js-ipfs with Rollup!</i></b>
<br />
<br />
<img src="https://raw.githubusercontent.com/jlord/forkngo/gh-pages/badges/cobalt.png" width="200">
<br>
<a href="https://github.com/ipfs/js-ipfs/tree/master/docs">Explore the docs</a>
·
<a href="https://codesandbox.io/">View Demo</a>
·
<a href="https://github.com/ipfs-examples/js-ipfs-examples/issues">Report Bug</a>
·
<a href="https://github.com/ipfs-examples/js-ipfs-examples/issues">Request Feature/Example</a>
</p>

## Table of Contents

- [Table of Contents](#table-of-contents)
- [About The Project](#about-the-project)
- [Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Installation and Running example](#installation-and-running-example)
- [Usage](#usage)
- [Documentation](#documentation)
- [Contributing](#contributing)
- [Want to hack on IPFS?](#want-to-hack-on-ipfs)

## About The Project

- Read the [docs](https://github.com/ipfs/js-ipfs/tree/master/docs)
- Look into other [examples](https://github.com/ipfs/js-ipfs/tree/master/examples) to learn how to spawn an IPFS node in Node.js and in the Browser
- Consult the [Core API docs](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api) to see what you can do with an IPFS node
- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it
- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs
- Check out https://docs.ipfs.io for tips, how-tos and more
- See https://blog.ipfs.io for news and more
- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io

## Getting Started

### Prerequisites

Make sure you have installed all of the following prerequisites on your development machine:

- Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed.
- Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager.

### Installation and Running example

```console
> npm install
> npm start
```

Now open your browser at `http://localhost:8888`

## Usage

In this example, you will find a boilerplate you can use to guide yourself into bundling js-ipfs with [rollup](http://rollupjs.org/), so that you can use it in your own web app!

You should see the following:

![](./img/1.png)
![](./img/2.png)

This example demonstrates the `Regular API`, top-level API for add, cat, get and ls Files on IPFS

_For more examples, please refer to the [Documentation](#documentation)_

## Documentation

- [Config](https://docs.ipfs.io/)
- [Core API](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api)
- [Examples](https://github.com/ipfs/js-ipfs/tree/master/examples)
- [Development](https://github.com/ipfs/js-ipfs/blob/master/docs/DEVELOPMENT.md)

## Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.

1. Fork the IPFS Project
2. Create your Feature Branch (`git checkout -b feature/amazing-feature`)
3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`)
4. Push to the Branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## Want to hack on IPFS?

[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)

The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:

Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md).

- **Check out existing issues** The [issue list](https://github.com/ipfs/js-ipfs/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/js-ipfs/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge
- **Look at the [IPFS Roadmap](https://github.com/ipfs/roadmap)** This are the high priority items being worked on right now
- **Perform code reviews** More eyes will help
a. speed the project along
b. ensure quality, and
c. reduce possible future bugs.
- **Add tests**. There can never be enough tests.
- **Join the [Weekly Core Implementations Call](https://github.com/ipfs/team-mgmt/issues/992)** it's where everyone discusses what's going on with IPFS and what's next
Binary file added examples/browser-rollup/favicon.ico
Binary file not shown.
Binary file added examples/browser-rollup/img/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/browser-rollup/img/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
125 changes: 125 additions & 0 deletions examples/browser-rollup/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bundle js-ipfs with rollup</title>

<link
rel="stylesheet"
href="https://unpkg.com/tachyons@4.10.0/css/tachyons.min.css"
/>
<link rel="stylesheet" href="https://unpkg.com/ipfs-css@0.12.0/ipfs.css" />
<link rel="shortcut icon" href="./favicon.ico" />

<script src="./index.js"></script>
<style>
::placeholder {
color: rgb(0 0 0 / 30%);
}

form {
margin: 1.25rem 0;
}

.window {
display: flex;
flex-direction: column;
background: #222;
color: #fff;
height: 400px;
}

.window .header {
flex-basis: 3rem;
background: #c6c6c6;
position: relative;
}

.window .header:after {
content: ". . .";
position: absolute;
left: 12px;
right: 0;
top: -3px;
font-family: "Times New Roman", Times, serif;
font-size: 96px;
color: #fff;
line-height: 0;
letter-spacing: -12px;
}

.terminal {
margin: 20px;
font-family: monospace;
font-size: 16px;
overflow: auto;
flex: 1;
}
</style>
</head>
<body class="montserrat f5">
<header class="flex items-center pa3 bg-navy bb bw3 b--aqua">
<a href="https://ipfs.io" title="home">
<img
alt="IPFS logo"
src="./public/ipfs-logo.svg"
style="height: 50px"
class="v-top"
/>
</a>
</header>

<main class="pa4-l bg-snow mw7 mv5 center pa4">
<h1 class="pa0 f2 ma0 mb4 aqua tc">Add data to IPFS from the browser</h1>

<form id="add-file">
<label for="file-name" class="f5 ma0 pb2 aqua fw4 db">Name</label>
<input
class="input-reset bn black-80 bg-white pa3 w-100 mb3"
id="file-name"
name="file-name"
type="text"
placeholder="file.txt"
required
/>

<label for="file-content" class="f5 ma0 pb2 aqua fw4 db">Content</label>
<input
class="input-reset bn black-80 bg-white pa3 w-100 mb3 ft"
id="file-content"
name="file-content"
type="text"
placeholder="Hello world"
required
/>

<button
class="
button-reset
pv3
tc
bn
bg-animate bg-black-80
hover-bg-aqua
white
pointer
w-100
"
id="add-submit"
type="submit"
>
Add file
</button>
</form>

<h3>Output</h3>

<div class="window">
<div class="header"></div>
<div id="terminal" class="terminal"></div>
</div>
</main>
</body>
</html>
32 changes: 32 additions & 0 deletions examples/browser-rollup/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "example-browser-browserify",
"description": "Bundle js-ipfs with Browserify",
"version": "1.0.0",
"main": "dist/index.html",
"private": true,
"scripts": {
"clean": "rimraf ./dist",
"build": "rollup -c",
"serve": "http-server dist -a 127.0.0.1 -p 8888",
"start": "npm run build && npm run serve",
"test:example": "npm run build && playwright test tests"
},
"keywords": [],
"license": "MIT",
"devDependencies": {
"@playwright/test": "^1.12.3",
"@rollup/plugin-commonjs": "^19.0.2",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"http-server": "^0.12.3",
"playwright": "^1.12.3",
"rimraf": "^3.0.2",
"rollup": "^2.54.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-polyfill-node": "^0.7.0",
"test-util-ipfs-example": "^1.0.2"
},
"dependencies": {
"ipfs": "^0.55.4"
}
}
1 change: 1 addition & 0 deletions examples/browser-rollup/public/ipfs-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions examples/browser-rollup/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import copy from 'rollup-plugin-copy'

const config = {
input: 'src/index.js',
output: {
file: 'dist/index.js',
format: 'esm',
},
context: 'globalThis',
plugins: [
copy({
targets: [
{ src: './index.html', dest: 'dist/' },
{ src: './favicon.ico', dest: 'dist/' },
{ src: 'public/**/*', dest: 'dist/public/' }
]
}),
nodePolyfills(),
nodeResolve({
browser: true,
preferBuiltins: false
}),
commonjs(),
json(),
]
};

export default config;
Loading