Prebid.js build options can be customized at bundle time by providing a loader or plugin that replaces the generated build options module. Supported integrations include the webpack loader and the Rollup-compatible plugin (Rollup, Vite, Rolldown). Both paths share the same virtual module protocol (details after the examples).
Use the webpack loader exported from prebid.js/customize/webpackLoader.
// webpack.conf.js
module.exports = {
module: {
rules: [
{
loader: 'prebid.js/customize/webpackLoader',
options: {
globalVarName: 'myCustomGlobal',
defineGlobal: true,
distUrlBase: 'https://cdn.example.com/prebid/chunks/'
}
},
]
}
}Use the Rollup-compatible plugin exported from prebid.js/customize/rollupPlugin.
// rollup.config.js
import prebidBuildOptions from 'prebid.js/customize/rollupPlugin'
export default {
plugins: [
prebidBuildOptions({
globalVarName: 'myCustomGlobal',
defineGlobal: true,
distUrlBase: 'https://cdn.example.com/prebid/chunks/'
})
]
}// vite.config.js
import { defineConfig } from 'vite'
import prebidBuildOptions from 'prebid.js/customize/rollupPlugin'
export default defineConfig({
plugins: [
prebidBuildOptions({
globalVarName: 'myCustomGlobal'
})
]
})The customization works by intercepting the generated module at dist/src/buildOptions.mjs and returning a virtual module that exports the merged options:
export default {
pbGlobal: "pbjs",
defineGlobal: true,
distUrlBase: "https://cdn.jsdelivr.net/npm/prebid.js/dist/chunks/"
}If you need to integrate with another bundler, reuse the helper exported from prebid.js/customize/virtualBuildOptions:
getBuildOptionsVirtualModuleId()returns the target module id to interceptrenderBuildOptionsVirtualModule(options)returns theexport default ...payload