Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Prebid.js as npm dependency #3435

Merged
merged 20 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
793d224
added babel plugin to replace webpack StringReplacementPlugin
snapwich Jan 3, 2019
a3a517e
remove ignore-loader in favor of filtering non .js files as modules
snapwich Jan 3, 2019
01a5c87
make all imports relative for projects not using our resolver
snapwich Jan 3, 2019
33f635a
refactor adaptermanager to adapterManager
snapwich Jan 3, 2019
3c0a71d
convert adapterManager to be compatible with latest version of babel
snapwich Jan 3, 2019
e053063
refactored utils with es6 exports
snapwich Jan 7, 2019
58d9751
fixing tests
snapwich Jan 7, 2019
832c6b1
fixing stubs and tests
snapwich Jan 8, 2019
e71b964
babelrc updated to be used externally from parent project
snapwich Jan 9, 2019
d696b8d
remove $prebid.version$ from gulp and add to babel plugin
snapwich Jan 9, 2019
e4fbd8f
fix tests to use actual prebid.version rather than string literal
snapwich Jan 9, 2019
f93130f
refactor all modules to use relative imports w/o webpack resolver
snapwich Jan 9, 2019
942be18
fix test in old safari
snapwich Jan 9, 2019
fa69ac8
update package-lock.json
snapwich Jan 9, 2019
ebbbc37
remove unnecessary json-loader
snapwich Jan 9, 2019
cfd21bb
update babel plugin to use same @babel/core
snapwich Jan 9, 2019
4812a3e
add instructions for using prebid as npm depenedency added to readme
snapwich Jan 10, 2019
d295fc2
remove unused variable in global babel plugin
snapwich Jan 10, 2019
fcbdfaf
fixed missing internal.createTrackPixelIframeHtml
snapwich Jan 15, 2019
95928f0
fix relative pathing for new modules
snapwich Jan 15, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .babelrc

This file was deleted.

34 changes: 34 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

let path = require('path');

function useLocal(module) {
return require.resolve(module, {
paths: [
__dirname
]
})
}

module.exports = {
"presets": [
[
useLocal('@babel/preset-env'),
{
"targets": {
"browsers": [
"chrome >= 61",
"safari >=8",
"edge >= 14",
"ff >= 57",
"ie >= 10",
"ios >= 8"
]
}
}
]
],
"plugins": [
path.resolve(__dirname, './plugins/pbjsGlobals.js'),
useLocal('babel-plugin-transform-object-assign')
]
};
83 changes: 83 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,94 @@ Working examples can be found in [the developer docs](http://prebid.org/dev-docs

**Table of Contents**

- [Usage](#Usage)
- [Install](#Install)
- [Build](#Build)
- [Run](#Run)
- [Contribute](#Contribute)

<a name="Usage"></a>

## Usage (as a npm dependency)

*Note:* Requires Prebid.js v1.38.0+

Prebid.js depends on Babel and some Babel Plugins in order to run correctly in the browser. Here are some examples for
configuring webpack to work with Prebid.js.

With Babel 7:
```javascript
// webpack.conf.js
let path = require('path');
module.exports = {
mode: 'production',
module: {
rules: [

// this rule can be excluded if you don't require babel-loader for your other application files
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
}
},

// this separate rule is required to make sure that the Prebid.js files are babel-ified. this rule will
// override the regular exclusion from above (for being inside node_modules).
{
test: /.js$/,
include: new RegExp(`\\${path.sep}prebid\.js`),
use: {
loader: 'babel-loader',
// presets and plugins for Prebid.js must be manually specified separate from your other babel rule.
// this can be accomplished by requiring prebid's .babelrc.js file (requires Babel 7 and Node v8.9.0+)
options: require('prebid.js/.babelrc.js')
}
}
]
}
}
```

Or for Babel 6 and/or Node v8.6.0 and less:
```javascript
// you must manually install and specify the presets and plugins yourself
options: {
plugins: [
"transform-object-assign", // required (for IE support) and "babel-plugin-transform-object-assign"
// must be installed as part of your package.
require('prebid.js/plugins/pbjsGlobals.js') // required!
],
presets: [
["env", { // you can use other presets if you wish.
"targets": { // this example is using "babel-presets-env", which must be installed if you
"browsers": [ // follow this example.
... // your browser targets. they should probably match the targets you're using for the rest
// of your application
]
}
}]
]
}
```

Then you can use Prebid.js as any other npm depedendency

```javascript
import prebid from 'prebid.js';
import 'prebid.js/modules/rubiconBidAdapter'; // imported modules will register themselves automatically with prebid
import 'prebid.js/modules/appnexusBidAdapter';
prebid.processQueue(); // required to process existing pbjs.queue blocks and setup any further pbjs.queue execution

prebid.requestBids({
...
})

```



<a name="Install"></a>

## Install
Expand Down
2 changes: 1 addition & 1 deletion gulpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = {
try {
var absoluteModulePath = path.join(__dirname, MODULE_PATH);
internalModules = fs.readdirSync(absoluteModulePath)
.filter(file => !(/(^|\/)\.[^\/\.]/g).test(file))
.filter(file => (/^[^\.]+(\.js)?$/).test(file))
.reduce((memo, file) => {
var moduleName = file.split(new RegExp('[.\\' + path.sep + ']'))[0];
var modulePath = path.join(absoluteModulePath, file);
Expand Down
2 changes: 0 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ function makeDevpackPkg() {
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
}
Expand All @@ -159,7 +158,6 @@ function makeWebpackPkg() {
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(replace('$prebid.version$', prebid.version))
.pipe(uglify())
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(optimizejs())
Expand Down
2 changes: 1 addition & 1 deletion modules/33acrossBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as utils from 'src/utils';
import * as utils from '../src/utils';

const { registerBidder } = require('../src/adapters/bidderFactory');
const { config } = require('../src/config');
Expand Down
4 changes: 2 additions & 2 deletions modules/a4gBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from 'src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';
import * as utils from '../src/utils';

const A4G_BIDDER_CODE = 'a4g';
const A4G_CURRENCY = 'USD';
Expand Down
4 changes: 2 additions & 2 deletions modules/aardvarkBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'aardvark';
const DEFAULT_ENDPOINT = 'bidder.rtk.io';
Expand Down
6 changes: 3 additions & 3 deletions modules/adagioAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Analytics Adapter for Adagio
*/

import adapter from 'src/AnalyticsAdapter';
import adaptermanager from 'src/adaptermanager';
import adapter from '../src/AnalyticsAdapter';
import adapterManager from '../src/adapterManager';

// This config makes Prebid.js call this function on each event:
// `window['AdagioPrebidAnalytics']('on', eventType, args)`
Expand All @@ -15,7 +15,7 @@ var adagioAdapter = adapter({
analyticsType: 'bundle'
});

adaptermanager.registerAnalyticsAdapter({
adapterManager.registerAnalyticsAdapter({
adapter: adagioAdapter,
code: 'adagio'
});
Expand Down
4 changes: 2 additions & 2 deletions modules/adagioBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import find from 'core-js/library/fn/array/find';
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'adagio';
const VERSION = '1.0.0';
Expand Down
6 changes: 3 additions & 3 deletions modules/adbutlerBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

import * as utils from 'src/utils';
import {config} from 'src/config';
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from '../src/utils';
import {config} from '../src/config';
import {registerBidder} from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'adbutler';

Expand Down
4 changes: 2 additions & 2 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import {registerBidder} from 'src/adapters/bidderFactory';
import { BANNER, VIDEO } from 'src/mediaTypes';
import {registerBidder} from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';

const BIDDER_CODE = 'adform';
export const spec = {
Expand Down
6 changes: 3 additions & 3 deletions modules/adformOpenRTBBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import {
registerBidder
} from 'src/adapters/bidderFactory';
} from '../src/adapters/bidderFactory';
import {
NATIVE
} from 'src/mediaTypes';
import * as utils from 'src/utils';
} from '../src/mediaTypes';
import * as utils from '../src/utils';

const BIDDER_CODE = 'adformOpenRTB';
const NATIVE_ASSET_IDS = { 0: 'title', 2: 'icon', 3: 'image', 5: 'sponsoredBy', 4: 'body', 1: 'cta' };
Expand Down
8 changes: 4 additions & 4 deletions modules/adgenerationBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import {BANNER, NATIVE} from 'src/mediaTypes';
import { config } from 'src/config';
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER, NATIVE} from '../src/mediaTypes';
import { config } from '../src/config';
const ADG_BIDDER_CODE = 'adgeneration';

export const spec = {
Expand Down
4 changes: 2 additions & 2 deletions modules/adheseBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER, VIDEO } from 'src/mediaTypes';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER, VIDEO } from '../src/mediaTypes';

const BIDDER_CODE = 'adhese';
const USER_SYNC_BASE_URL = 'https://user-sync.adhese.com/iframe/user_sync.html';
Expand Down
6 changes: 3 additions & 3 deletions modules/adikteevBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {registerBidder} from 'src/adapters/bidderFactory';
import {BANNER} from 'src/mediaTypes';
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER} from '../src/mediaTypes';
import * as utils from '../src/utils';
import {config} from 'src/config';
import {config} from '../src/config';

export const BIDDER_CODE = 'adikteev';
export const ENDPOINT_URL = 'https://serve-adserver.adikteev.com/api/prebid/bid';
Expand Down
22 changes: 13 additions & 9 deletions modules/adkernelAdnAnalyticsAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import adapter from 'src/AnalyticsAdapter';
import CONSTANTS from 'src/constants.json';
import adaptermanager from 'src/adaptermanager';
import {parse} from 'src/url';
import * as utils from 'src/utils';
import {ajax} from 'src/ajax';
import adapter from '../src/AnalyticsAdapter';
import CONSTANTS from '../src/constants.json';
import adapterManager from '../src/adapterManager';
import {parse} from '../src/url';
import * as utils from '../src/utils';
import {ajax} from '../src/ajax';

const ANALYTICS_VERSION = '1.0.0';
const DEFAULT_QUEUE_TIMEOUT = 4000;
Expand Down Expand Up @@ -99,7 +99,7 @@ analyticsAdapter.enableAnalytics = (config) => {
analyticsAdapter.originEnableAnalytics(config);
};

adaptermanager.registerAnalyticsAdapter({
adapterManager.registerAnalyticsAdapter({
adapter: analyticsAdapter,
code: 'adkernelAdn'
});
Expand All @@ -110,11 +110,15 @@ function sendAll() {
let events = analyticsAdapter.context.queue.popAll();
if (events.length !== 0) {
let req = Object.assign({}, analyticsAdapter.context.requestTemplate, {hb_ev: events});
ajax(`//${analyticsAdapter.context.host}/hb-analytics`, () => {
}, JSON.stringify(req));
analyticsAdapter.ajaxCall(JSON.stringify(req));
}
}

analyticsAdapter.ajaxCall = function ajaxCall(data) {
ajax(`//${analyticsAdapter.context.host}/hb-analytics`, () => {
}, data);
};

function trackAuctionInit() {
analyticsAdapter.context.auctionTimeStart = Date.now();
const event = createHbEvent(undefined, ADK_HB_EVENTS.AUCTION_INIT);
Expand Down
6 changes: 3 additions & 3 deletions modules/adkernelAdnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import {BANNER, VIDEO} from 'src/mediaTypes';
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';
import {BANNER, VIDEO} from '../src/mediaTypes';
import includes from 'core-js/library/fn/array/includes';

const DEFAULT_ADKERNEL_DSP_DOMAIN = 'tag.adkernel.com';
Expand Down
8 changes: 4 additions & 4 deletions modules/adkernelBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as utils from 'src/utils';
import { BANNER, VIDEO } from 'src/mediaTypes';
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from '../src/utils';
import { BANNER, VIDEO } from '../src/mediaTypes';
import {registerBidder} from '../src/adapters/bidderFactory';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';
import {parse as parseUrl} from 'src/url'
import {parse as parseUrl} from '../src/url'

const VIDEO_TARGETING = ['mimes', 'minduration', 'maxduration', 'protocols',
'startdelay', 'linearity', 'boxingallowed', 'playbackmethod', 'delivery',
Expand Down
6 changes: 3 additions & 3 deletions modules/adliveBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';
import { BANNER } from '../src/mediaTypes';

const BIDDER_CODE = 'adlive';
const ENDPOINT_URL = 'https://api.publishers.adlive.io/get?pbjs=1';
Expand Down
4 changes: 2 additions & 2 deletions modules/admaticBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'admatic';
const ENDPOINT_URL = '//ads4.admatic.com.tr/prebid/v3/bidrequest';
Expand Down
4 changes: 2 additions & 2 deletions modules/admixerBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';
import * as utils from '../src/utils';
import {registerBidder} from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'admixer';
const ENDPOINT_URL = '//inv-nets.admixer.net/prebid.1.0.aspx';
Expand Down
4 changes: 2 additions & 2 deletions modules/adoceanBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import * as utils from '../src/utils';
import { registerBidder } from '../src/adapters/bidderFactory';

const BIDDER_CODE = 'adocean';

Expand Down
Loading