Skip to content

Commit

Permalink
Merge pull request #14 from yahoo/changes
Browse files Browse the repository at this point in the history
No longer need to swap fetcher.js and fetcher.client.js manually via webpack
  • Loading branch information
Vijar committed Sep 3, 2014
2 parents 7bfe3ed + c046b61 commit 7d6bc82
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 23 deletions.
15 changes: 0 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,6 @@ var fetchr = require('fetchr'),
//...
```


## 5. Swap Fetchr <=> Fetchr.client

Fetchr relies on a build process that swaps out `lib/fetchr.js` with `lib/fetchr.client.js` in the bundle that is generated for client side use. Usually the bundle is generated using tools like [webpack](http://webpack.github.io/) or [browserify](http://browserify.org/).

```
//webpack config
plugins: [
//...
//Replace fetcher lib with client side fetcher lib
new webpack.NormalModuleReplacementPlugin(/^fetchr$/, require.resolve('fetchr/libs/fetcher.client.js'))
//...
]
```

# Usage Examples

See the [simple example](https://github.com/yahoo/fetchr/tree/master/examples/simple)
Expand Down
8 changes: 1 addition & 7 deletions examples/simple/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
* Copyright 2014, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
var webpack = require('webpack'),
path = require('path');
module.exports = {
entry: require.resolve('./client/app.js'),
output: {
path: __dirname+'/client/build/',
filename: "app.js"
},
plugins: [
//Replace fetcher lib with client side fetcher lib
new webpack.NormalModuleReplacementPlugin(/^..\/..\/..\/libs\/fetcher.js$/, path.resolve('../../libs/fetcher.client.js'))
]
}
};
2 changes: 1 addition & 1 deletion libs/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = function createFetcherClass (options) {
config: {},
callback: function (err, data) {
if (err) {
res.send('400', 'request failed');
res.status('400').send('request failed');
}
res.json(data);
}
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"mockery": "^1.4.0",
"precommit-hook": "^1.0.2"
},
"browser": {
"./libs/fetcher.js": "./libs/fetcher.client.js"
},
"jshintConfig": {
"node": true
},
Expand Down

0 comments on commit 7d6bc82

Please sign in to comment.