Last active
August 19, 2016 05:50
-
-
Save kristian76/c8c4a30c327caa1d5be69a53638beb99 to your computer and use it in GitHub Desktop.
Gun and webpack
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
var express = require('express'), | |
app = express(); | |
var Gun = require('gun'); | |
var gun = Gun({ | |
file: 'data.json' | |
}); | |
gun.wsp(app); | |
app.use(express.static(__dirname)).listen(9000); |
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
<!doctype html> | |
<html lang=""> | |
<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></title> | |
<meta name="description" content=""> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="apple-touch-icon" href="apple-touch-icon.png"> | |
<!-- Place favicon.ico in the root directory --> | |
<!-- | |
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"> | |
<link rel="stylesheet" href="https://code.getmdl.io/1.1.3/material.indigo-pink.min.css"> | |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css"> | |
<script defer src="https://code.getmdl.io/1.1.3/material.min.js"></script> | |
//--> | |
<srcipt src="http://localhost:9000/gun.js"></script> | |
</head> | |
<body> | |
<!--[if lt IE 8]> | |
<p class="browserupgrade">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> | |
<![endif]--> | |
<div id="appmount"></div> | |
<script src="/js/bundle.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
/** | |
* Setup Gun | |
* TODO: add peers | |
*/ | |
// var Gun = require('gun/gun'); | |
var peers = [ | |
'http://localhost:9000/gun' | |
]; | |
var gun = Gun(peers); | |
var React = require('react'); | |
var ReactDom = require('react-dom'); | |
var App = React.createClass({ | |
getInitialState() { | |
return {issues: []}; | |
}, | |
loadData() { | |
this.setState({issues: []}); | |
var issues = []; | |
gun.get('issues').map(function(node) { | |
console.log('__loadData'); | |
issues.push(node); | |
}); | |
this.setState({issues: issues}); | |
}, | |
componentDidMount() { | |
}, | |
handleOnClick(e) { | |
e.preventDefault(); | |
var company = gun.get('startup/hype').put({ | |
name: 'hype' | |
}); | |
company.val(function(node) { | |
console.log('hype ', node); | |
}); | |
var alice = gun.get('person/alice').put({ name: 'Alice' }); | |
alice.val(function(node) { | |
console.log('Alice ', node); | |
}); | |
var people = gun.get('people'); | |
people.set(alice); | |
people.map(function(person) { | |
console.log('person ', person); | |
}); | |
}, | |
render() { | |
console.log(this.state); | |
return <div> | |
<a href="" onClick={ this.handleOnClick }>Add Issue</a> | |
</div> | |
} | |
}); | |
var ROOT = document.getElementById('appmount'); | |
ReactDom.render( | |
<App />, | |
ROOT | |
); |
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
{ | |
"name": "workbench", | |
"version": "1.0.0", | |
"description": "My local workbench", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "cd public && serve" | |
}, | |
"author": "[email protected]", | |
"license": "ISC", | |
"dependencies": { | |
"babel-core": "^6.7.7", | |
"babel-preset-stage-1": "^6.5.0", | |
"babel-preset-stage-2": "^6.5.0", | |
"express": "^4.14.0", | |
"fetch": "^1.0.1", | |
"react": "^0.14.8", | |
"react-dom": "^0.14.8", | |
"react-router": "^2.3.0" | |
}, | |
"devDependencies": { | |
"babel-core": "^6.5.2", | |
"babel-loader": "^6.2.4", | |
"babel-preset-es2015": "^6.5.0", | |
"babel-preset-react": "^6.5.0", | |
"bufferutil": "^1.2.1", | |
"gun": "^0.3.992", | |
"json-loader": "^0.5.4", | |
"loader-utils": "^0.2.15", | |
"prime": "^0.5.0", | |
"primes": "0.0.1", | |
"tls": "0.0.1", | |
"url": "^0.11.0", | |
"utf-8-validate": "^1.2.1", | |
"webpack": "^2.1.0-beta.5" | |
} | |
} |
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
var path = require('path'), | |
webpack = require('webpack'); | |
module.exports = { | |
devtool: 'source-map', | |
target: 'web', | |
node: { | |
fs: 'empty' | |
}, | |
entry: { | |
workboard: './src/workboard/main.js' | |
}, | |
output: { | |
path: __dirname, filename: '/public/[name]/js/bundle.js' | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /.js?$/, | |
loader: 'babel-loader', | |
exclude: /node_modules/, | |
query: { | |
presets: ['es2015', 'react', 'stage-2', 'stage-1'] | |
} | |
}, | |
{ | |
test: /\.json$/, | |
loader: 'json', | |
include: [ | |
/node_modules/ | |
] | |
} | |
], | |
noParse: [/aws-sdk/] | |
}, | |
plugins: [ | |
new webpack.DefinePlugin({ "global.GENTLY": false }) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment