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

Commit 3b846b0

Browse files
authored
feat: add esbuild example (#404)
Adds a very simple esbuild example
1 parent b2fd458 commit 3b846b0

File tree

15 files changed

+488
-2
lines changed

15 files changed

+488
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
- browser-add-readable-stream
1717
- browser-angular
1818
- browser-create-react-app
19+
- browser-esbuild
1920
- browser-exchange-files
2021
- browser-ipns-publish
2122
- browser-lit
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
**IMPORTANT: Please do not create a Pull Request for this repository.**
2+
3+
The contents of this repository are automatically synced from the parent [IPFS Examples Project](https://github.com/ipfs-examples/js-ipfs-examples) so any changes made to the standalone repository will be lost after the next sync.
4+
5+
Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/js-ipfs-examples) instead.
6+
7+
## Contributing
8+
9+
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**.
10+
11+
1. Fork the [IPFS Examples Project](https://github.com/ipfs-examples/js-ipfs-examples)
12+
2. Create your Feature Branch (`git checkout -b feature/amazing-example`)
13+
3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`)
14+
4. Push to the Branch (`git push origin feature/amazing-example`)
15+
5. Open a Pull Request
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Sync
2+
on:
3+
workflow_dispatch:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
7+
jobs:
8+
sync:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- name: Pull from another repository
13+
uses: ipfs-examples/actions-pull-directory-from-repo@main
14+
with:
15+
source-repo: "ipfs-examples/js-ipfs-examples"
16+
source-folder-path: "examples/browser-esbuild"
17+
source-branch: "master"
18+
target-branch: "main"
19+
git-username: github-actions
20+
git-email: github-actions@github.com

examples/browser-esbuild/README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<p align="center">
2+
<a href="https://js.ipfs.io" title="JS IPFS">
3+
<img src="https://ipfs.io/ipfs/Qme6KJdKcp85TYbLxuLV7oQzMiLremD7HMoXLZEmgo6Rnh/js-ipfs-sticker.png" alt="IPFS in JavaScript logo" width="244" />
4+
</a>
5+
</p>
6+
7+
<h3 align="center"><b>js-ipfs with esbuild</b></h3>
8+
9+
<p align="center">
10+
<b><i>Bundle js-ipfs with esbuil!</i></b>
11+
<br />
12+
<br />
13+
<img src="https://raw.githubusercontent.com/jlord/forkngo/gh-pages/badges/cobalt.png" width="200">
14+
<br>
15+
<a href="https://github.com/ipfs/js-ipfs/tree/master/docs">Explore the docs</a>
16+
·
17+
<a href="https://codesandbox.io/">View Demo</a>
18+
·
19+
<a href="https://github.com/ipfs-examples/js-ipfs-examples/issues">Report Bug</a>
20+
·
21+
<a href="https://github.com/ipfs-examples/js-ipfs-examples/issues">Request Feature/Example</a>
22+
</p>
23+
24+
## Table of Contents
25+
26+
- [Table of Contents](#table-of-contents)
27+
- [About The Project](#about-the-project)
28+
- [Getting Started](#getting-started)
29+
- [Prerequisites](#prerequisites)
30+
- [Installation and Running example](#installation-and-running-example)
31+
- [Usage](#usage)
32+
- [References](#references)
33+
- [Documentation](#documentation)
34+
- [Contributing](#contributing)
35+
- [Want to hack on IPFS?](#want-to-hack-on-ipfs)
36+
37+
## About The Project
38+
39+
- Read the [docs](https://github.com/ipfs/js-ipfs/tree/master/docs)
40+
- Look into other [examples](https://github.com/ipfs-examples/js-ipfs-examples) to learn how to spawn an IPFS node in Node.js and in the Browser
41+
- 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
42+
- Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it
43+
- Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs
44+
- Check out https://docs.ipfs.io for tips, how-tos and more
45+
- See https://blog.ipfs.io for news and more
46+
- Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io
47+
48+
## Getting Started
49+
50+
### Prerequisites
51+
52+
Make sure you have installed all of the following prerequisites on your development machine:
53+
54+
- Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed.
55+
- Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager.
56+
57+
### Installation and Running example
58+
59+
```console
60+
> npm install
61+
> npm start
62+
```
63+
64+
Now open your browser at `http://localhost:8888`
65+
66+
## Usage
67+
68+
In this example, you will find a boilerplate you can use to guide yourself into bundling js-ipfs with [esbuild](https://esbuild.github.io/), so that you can use it in your own web app!
69+
70+
You should see the following:
71+
72+
![](./img/1.png)
73+
![](./img/2.png)
74+
75+
This example demonstrates the `Regular API`, top-level API for add, cat, get and ls Files on IPFS
76+
77+
_For more examples, please refer to the [Documentation](#documentation)_
78+
79+
## References
80+
81+
- Documentation:
82+
- [IPFS CONFIG](https://github.com/ipfs/js-ipfs/blob/master/docs/CONFIG.md)
83+
- [MISCELLANEOUS](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/MISCELLANEOUS.md)
84+
- [FILES](https://github.com/ipfs/js-ipfs/blob/master/docs/core-api/FILES.md)
85+
- Tutorials:
86+
- [MFS API](https://proto.school/mutable-file-system)
87+
- [Regular File API](https://proto.school/regular-files-api)
88+
89+
## Documentation
90+
91+
- [Config](https://docs.ipfs.io/)
92+
- [Core API](https://github.com/ipfs/js-ipfs/tree/master/docs/core-api)
93+
- [Examples](https://github.com/ipfs-examples/js-ipfs-examples)
94+
- [Development](https://github.com/ipfs/js-ipfs/blob/master/docs/DEVELOPMENT.md)
95+
- [Tutorials](https://proto.school)
96+
97+
## Contributing
98+
99+
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**.
100+
101+
1. Fork the IPFS Project
102+
2. Create your Feature Branch (`git checkout -b feature/amazing-feature`)
103+
3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`)
104+
4. Push to the Branch (`git push origin feature/amazing-feature`)
105+
5. Open a Pull Request
106+
107+
## Want to hack on IPFS?
108+
109+
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md)
110+
111+
The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out:
112+
113+
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).
114+
115+
- **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
116+
- **Look at the [IPFS Roadmap](https://github.com/ipfs/roadmap)** This are the high priority items being worked on right now
117+
- **Perform code reviews** More eyes will help
118+
a. speed the project along
119+
b. ensure quality, and
120+
c. reduce possible future bugs.
121+
- **Add tests**. There can never be enough tests.
122+
- **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

examples/browser-esbuild/esbuild.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { build } from 'esbuild'
2+
3+
build({
4+
entryPoints: ['./src/index.js'],
5+
outfile: './dist/index.js',
6+
sourcemap: 'external',
7+
minify: true,
8+
bundle: true,
9+
define: {
10+
'process.env.NODE_DEBUG': 'false',
11+
'global': 'globalThis'
12+
}
13+
})
14+
.catch(() => process.exit(1))

examples/browser-esbuild/favicon.ico

33.7 KB
Binary file not shown.

examples/browser-esbuild/img/1.png

205 KB
Loading

examples/browser-esbuild/img/2.png

253 KB
Loading

examples/browser-esbuild/package.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "example-browser-esbuild",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module",
6+
"description": "Bundle js-ipfs with esbuild",
7+
"keywords": [],
8+
"license": "ISC",
9+
"author": "",
10+
"scripts": {
11+
"clean": "rimraf ./dist",
12+
"build": "mkdir -p dist && cp src/index.html src/style.css src/ipfs-logo.svg dist && node esbuild.js",
13+
"start": "npm run build && esbuild --servedir=dist",
14+
"test": "npm run build && playwright test tests"
15+
},
16+
"browserslist": "last 1 Chrome version",
17+
"dependencies": {
18+
"ipfs-core": "^0.16.0"
19+
},
20+
"devDependencies": {
21+
"@babel/core": "^7.14.8",
22+
"@playwright/test": "^1.12.3",
23+
"esbuild": "^0.15.7",
24+
"playwright": "^1.12.3",
25+
"process": "^0.11.10",
26+
"rimraf": "^3.0.2",
27+
"test-util-ipfs-example": "^1.0.2",
28+
"util": "^0.12.4"
29+
}
30+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Bundle js-ipfs with parcel.js</title>
8+
9+
<link
10+
rel="stylesheet"
11+
href="https://unpkg.com/tachyons@4.10.0/css/tachyons.min.css"
12+
crossorigin
13+
/>
14+
<link
15+
rel="stylesheet"
16+
href="https://unpkg.com/ipfs-css@0.12.0/ipfs.css"
17+
crossorigin
18+
/>
19+
<link rel="shortcut icon" href="favicon.ico" />
20+
<link rel="stylesheet" href="./style.css" />
21+
22+
<script type="module" defer src="./index.js"></script>
23+
</head>
24+
<body class="montserrat f5">
25+
<header class="flex items-center pa3 bg-navy bb bw3 b--aqua">
26+
<a href="https://ipfs.io" title="home">
27+
<img
28+
alt="IPFS logo"
29+
src="./ipfs-logo.svg"
30+
style="height: 50px"
31+
class="v-top"
32+
/>
33+
</a>
34+
</header>
35+
36+
<main class="pa4-l bg-snow mw7 mv5 center pa4">
37+
<h1 class="pa0 f2 ma0 mb4 aqua tc">Add data to IPFS from the browser</h1>
38+
39+
<form id="add-file">
40+
<label for="file-name" class="f5 ma0 pb2 aqua fw4 db">Name</label>
41+
<input
42+
class="input-reset bn black-80 bg-white pa3 w-100 mb3"
43+
id="file-name"
44+
name="file-name"
45+
type="text"
46+
placeholder="file.txt"
47+
required
48+
/>
49+
50+
<label for="file-content" class="f5 ma0 pb2 aqua fw4 db">Content</label>
51+
<input
52+
class="input-reset bn black-80 bg-white pa3 w-100 mb3 ft"
53+
id="file-content"
54+
name="file-content"
55+
type="text"
56+
placeholder="Hello world"
57+
required
58+
/>
59+
60+
<button
61+
class="
62+
button-reset
63+
pv3
64+
tc
65+
bn
66+
bg-animate bg-black-80
67+
hover-bg-aqua
68+
white
69+
pointer
70+
w-100
71+
"
72+
id="add-submit"
73+
type="submit"
74+
>
75+
Add file
76+
</button>
77+
</form>
78+
79+
<h3>Output</h3>
80+
81+
<div class="window">
82+
<div class="header"></div>
83+
<div id="terminal" class="terminal"></div>
84+
</div>
85+
</main>
86+
</body>
87+
</html>

0 commit comments

Comments
 (0)