Skip to content

Commit f5b8f32

Browse files
committed
add instructions for using prebid as npm depenedency added to readme
1 parent 3cca39f commit f5b8f32

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

README.md

+83
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,94 @@ Working examples can be found in [the developer docs](http://prebid.org/dev-docs
1616

1717
**Table of Contents**
1818

19+
- [Usage](#Usage)
1920
- [Install](#Install)
2021
- [Build](#Build)
2122
- [Run](#Run)
2223
- [Contribute](#Contribute)
2324

25+
<a name="Usage"></a>
26+
27+
## Usage (as a npm dependency)
28+
29+
*Note:* Requires Prebid.js v1.38.0+
30+
31+
Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for
32+
configuring webpack to work with Prebid.js.
33+
34+
With Babel 7:
35+
```javascript
36+
// webpack.conf.js
37+
let path = require('path');
38+
module.exports = {
39+
mode: 'production',
40+
module: {
41+
rules: [
42+
43+
// this rule can be excluded if you don't require babel-loader for your other application files
44+
{
45+
test: /\.m?js$/,
46+
exclude: /node_modules/,
47+
use: {
48+
loader: 'babel-loader',
49+
}
50+
},
51+
52+
// this separate rule is required to make sure that the Prebid.js files are babel-ified. this rule will
53+
// override the regular exclusion from above (for being inside node_modules).
54+
{
55+
test: /.js$/,
56+
include: new RegExp(`\\${path.sep}prebid\.js`),
57+
use: {
58+
loader: 'babel-loader',
59+
// presets and plugins for Prebid.js must be manually specified separate from your other babel rule.
60+
// this can be accomplished by requiring prebid's .babelrc.js file (requires Babel 7 and Node v8.9.0+)
61+
options: require('prebid.js/.babelrc.js')
62+
}
63+
}
64+
]
65+
}
66+
}
67+
```
68+
69+
Or for Babel 6 and/or Node v8.6.0 and less:
70+
```javascript
71+
// you must manually install and specify the presets and plugins yourself
72+
options: {
73+
plugins: [
74+
"transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign"
75+
// must be installed as part of your package.
76+
require('prebid.js/plugins/pbjsGlobals.js') // required!
77+
],
78+
presets: [
79+
["env", { // you can use other presets if you wish.
80+
"targets": { // this example is using "babel-presets-env", which must be installed if you
81+
"browsers": [ // follow this example.
82+
... // your browser targets. they should probably match the targets you're using for the rest
83+
// of your application
84+
]
85+
}
86+
}]
87+
]
88+
}
89+
```
90+
91+
Then you can use Prebid.js as any other npm depedendency
92+
93+
```javascript
94+
import prebid from 'prebid.js';
95+
import 'prebid.js/modules/rubiconBidAdapter'; // imported modules will register themselves automatically with prebid
96+
import 'prebid.js/modules/appnexusBidAdapter';
97+
prebid.processQueue(); // required to process existing pbjs.queue blocks and setup any further pbjs.queue execution
98+
99+
prebid.requestBids({
100+
...
101+
})
102+
103+
```
104+
105+
106+
24107
<a name="Install"></a>
25108

26109
## Install

0 commit comments

Comments
 (0)