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

Registering a custom global name when importing prebid.js as a module #3479

Closed
bwnodak opened this issue Jan 24, 2019 · 5 comments
Closed

Registering a custom global name when importing prebid.js as a module #3479

bwnodak opened this issue Jan 24, 2019 · 5 comments
Assignees

Comments

@bwnodak
Copy link

bwnodak commented Jan 24, 2019

Type of issue

Question and/or Feature Request

Description

I'm importing prebid.js as a module thanks to v1.38, which is awesome, thank you so much for implementing this.

I notice this registers window.pbjs, which becomes a problem if another instance of prebid is on the page of a different version, or with different bidders registered. To get around this previously, I'd set the globalVarName in package.json, but installing with npm seems to preclude this as a viable solution.

Is there a good way to change the global name when using prebid.js as an npm module? I've written a script to be run during the app build process that renames the globalVarName in /node_modules/prebid.js/package.json, but it's quite a hack.

Platform details

[email protected]+

@snapwich
Copy link
Collaborator

With the release of 2.0 I've added an option to the babel-plugin that writes the global.

If you're using the loader instructions in the README, you should be able to pass the variable using the loader with something similar to the following:

let options = require('prebid.js/.babelrc.js');
options.plugins[0] = [options.plugins[0], {
  globalVarName: 'pbjs'
}];

...
// and then in webpack config
use: {
  loader: 'babel-loader',
  options: options
}

@bretg
Copy link
Collaborator

bretg commented Feb 7, 2019

@yonbeastie - Going to assume that snapwich has you covered here. Re-open as needed.

@holms
Copy link

holms commented May 20, 2021

@snapwich is there's any way to change this var from prebid_js_build_generator repo? I've really need to generate prebid.js with my own globalVarName. Is there's a way just to pass some ENV param, let's say for a Dockerfile..? Or if this requires some PR I'd be happy to contribute.

@gglas
Copy link

gglas commented Jul 19, 2021

Closing this issue, following here prebid/prebid-js-build-generator#15

@gglas gglas closed this as completed Jul 19, 2021
@Tharushan
Copy link

Tharushan commented Apr 20, 2023

With the release of 2.0 I've added an option to the babel-plugin that writes the global.

If you're using the loader instructions in the README, you should be able to pass the variable using the loader with something similar to the following:

let options = require('prebid.js/.babelrc.js');
options.plugins[0] = [options.plugins[0], {
  globalVarName: 'pbjs'
}];

...
// and then in webpack config
use: {
  loader: 'babel-loader',
  options: options
}

Note for people still using this fix, as it was reworked in new Prebid.Js versions you will need to use something like :

let options = require('prebid.js/babelConfig.js')({
  globalVarName: 'pbjs'
});

...
// and then in webpack config
use: {
  loader: 'babel-loader',
  options: options
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants