Skip to content
Snippets Groups Projects
Commit f47d6d6d authored by yamadapc's avatar yamadapc
Browse files

Add webpack usage example #200

This closes #200
parent 6f0bd996
No related branches found
No related tags found
No related merge requests found
...@@ -44,6 +44,9 @@ https://cdn.steemjs.com/lib/latest/steem.min.js<br/> ...@@ -44,6 +44,9 @@ https://cdn.steemjs.com/lib/latest/steem.min.js<br/>
<script src="//cdn.steemjs.com/lib/latest/steem.min.js"></script> <script src="//cdn.steemjs.com/lib/latest/steem.min.js"></script>
``` ```
## Webpack
[Please have a look at the webpack usage example.](https://github.com/steemit/steem-js/blob/master/examples/webpack-example)
## Server ## Server
## Install ## Install
``` ```
......
node-bundle.js
bundle.js
# `steem-js` webpack configuration example
This is a demo of `steem-js` and webpack usage targetting both the Web and
Node.js platforms.
## Minimal configuration
`steem-js` requires JSON files internally, so you need JSON loader configured:
```json
{
...
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader'},
]
}
...
}
```
Make sure `resolve.extensions` and `json-loader`'s `module.loaders[...].exclude`
do not exclude `.json` files or `node_modules` from resolving.
## Compiling the example
Compiling for the web (`bundle.js`, which you can test with `open index.html`):
```
webpack
```
Compiling for node.js (`node-bundle.js`, which you can test with `node node-bundle.js`):
```
USE_NODE=1 webpack
```
<script src="bundle.js"></script>
This diff is collapsed.
{
"name": "steem-js-webpack-example",
"scripts": {
"build": "npm run build-web && npm run build-node",
"build-web": "webpack",
"build-node": "USE_NODE=1 webpack"
},
"devDependencies": {
"json-loader": "^0.5.4",
"webpack": "^3.0.0"
},
"dependencies": {
"steem": "^0.5.20"
}
}
const steem = require('steem/lib/browser');
console.log('Getting post content...');
const resultP = steem.api.getContentAsync('yamadapc', 'test-1-2-3-4-5-6-7-9');
resultP.then(result => console.log(result));
module.exports = {
entry: './src/index.js',
target: process.env.USE_NODE ? 'node' : 'web',
output: {
filename: process.env.USE_NODE ? 'node-bundle.js' : 'bundle.js'
},
module: {
loaders: [
{ test: /\.json$/, loader: 'json-loader'},
]
},
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment