This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
docs: add parceljs browser example #1726
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eadad92
docs: add parceljs browser example
raoulmillais 170cbc7
docs: add link to parceljs example
raoulmillais b04cfcc
doc: make babel transpile less aggressively
raoulmillais e0cdd37
chore: rename parceljs example package
raoulmillais 381b35d
docs: reword parceljs example success message
raoulmillais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["@babel/preset-env"], | ||
"plugins": ["syntax-async-functions","transform-regenerator"] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
dist/ | ||
/node_modules/ | ||
.nvmrc | ||
.cache | ||
npm-debug.log | ||
.DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Bundle js-ipfs with [Parcel.js](https://parceljs.org/) | ||
|
||
> In this example, you will find a boilerplate application that connects to | ||
IPFS using JS-IPFS and is bundled with [Parcel.js](https://parceljs.org/), so | ||
that you can follow it for creating Parcel.js bundled js-ipfs DApps. | ||
|
||
## Before you start | ||
|
||
1. Start your IPFS daemon of choice e.g. `ipfs daemon` (optional if you do not | ||
want to serve the example over IPFS) | ||
1. Open a new terminal | ||
1. `cd` into this folder | ||
1. Run `npm install` | ||
|
||
## Running this example in development mode with auto-reloading | ||
|
||
1. `npm start` | ||
1. Open your browser at `http://localhost:1234` | ||
|
||
You should see the following: | ||
|
||
 | ||
|
||
## Build and add to IPFS | ||
|
||
1. Clear the contents of `dist` if this is not the first time you are building | ||
e.g. `rm -r dist` on a unix system | ||
1. `npm run build` | ||
1. The production build of the site is now in the `dist` folder | ||
1. Add the folder to ipfs using your IPFS client of choice e.g. | ||
`ipfs add -r dist` | ||
|
||
The last hash output is the hash of the directory. This can be used to access | ||
this example served over IPFS and will be accessible by a public gateway: | ||
|
||
> https://ipfs.io/ipfs/<hash_of_directory>/ | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "playground", | ||
raoulmillais marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"browserslist": [ | ||
"last 2 Chrome versions" | ||
], | ||
"scripts": { | ||
"lint": "standard public/**/*.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"start": "parcel public/index.html", | ||
"build": "parcel build public/index.html --public-url ./" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"ipfs": "file:../../" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.1.5", | ||
"@babel/core": "^7.1.6", | ||
"@babel/preset-env": "^7.1.6", | ||
"babel-plugin-syntax-async-functions": "^6.13.0", | ||
"babel-plugin-transform-regenerator": "^6.26.0", | ||
"babel-polyfill": "^6.26.0", | ||
"parcel-bundler": "^1.10.3", | ||
"standard": "^12.0.1" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
|
||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title>js-ipfs parcel.js browser example</title> | ||
</head> | ||
|
||
<body> | ||
<header> | ||
<h1 id="status">Connecting to IPFS...</h1> | ||
</header> | ||
|
||
<main> | ||
<pre id="output"></pre> | ||
</main> | ||
|
||
<script src="./index.js"></script> | ||
|
||
</body> | ||
|
||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import 'babel-polyfill' | ||
import IPFS from 'ipfs' | ||
|
||
// IPFS node setup | ||
const node = new IPFS({ repo: String(Math.random() + Date.now()) }) | ||
|
||
// UI elements | ||
const status = document.getElementById('status') | ||
const output = document.getElementById('output') | ||
|
||
output.textContent = '' | ||
|
||
function log (txt) { | ||
console.info(txt) | ||
output.textContent += `${txt.trim()}\n` | ||
} | ||
|
||
node.on('ready', async () => { | ||
status.innerText = 'Connected to IPFS :)' | ||
|
||
const version = await node.version() | ||
|
||
log(`The IPFS node version is ${version.version}`) | ||
|
||
const filesAdded = await node.add({ | ||
path: 'hello-parcel.txt', | ||
content: Buffer.from('Hello from parcel.js bundled ipfs example') | ||
}) | ||
|
||
log(`This page added ${filesAdded[0].path} to IPFS and its hash is ${filesAdded[0].hash}`) | ||
|
||
const fileBuffer = await node.cat(filesAdded[0].hash) | ||
|
||
log(`The contents of the file was: ${fileBuffer.toString()}`) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.