Skip to content

Commit

Permalink
Optimize splitChunk config; import paapi from fledgeFromGpt (#11269)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Apr 3, 2024
1 parent cddb934 commit c27f64b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 1 addition & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ function bundle(dev, moduleArr) {
[coreFile].concat(moduleFiles).map(name => path.basename(name)).forEach((file) => {
(depGraph[file] || []).forEach((dep) => dependencies.add(helpers.getBuiltPath(dev, dep)));
});

const entries = [coreFile].concat(Array.from(dependencies), moduleFiles);
const entries = _.uniq([coreFile].concat(Array.from(dependencies), moduleFiles));

var outputFileName = argv.bundleName ? argv.bundleName : 'prebid.js';

Expand Down
5 changes: 5 additions & 0 deletions modules/fledgeForGpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import {getGptSlotForAdUnitCode} from '../libraries/gptUtils/gptUtils.js';
import {config} from '../src/config.js';
import {getGlobal} from '../src/prebidGlobal.js';

// import parent module to keep backwards-compat for NPM consumers after paapi was split from fledgeForGpt
// there's a special case in webpack.conf.js to avoid duplicating build output on non-npm builds
// TODO: remove this in prebid 9
// eslint-disable-next-line prebid/validate-imports
import './paapi.js';
const MODULE = 'fledgeForGpt';

let getPAAPIConfig;
Expand Down
23 changes: 22 additions & 1 deletion webpack.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,31 @@ module.exports = {
return [lib, def];
})
);
const core = path.resolve('./src');
const paapiMod = path.resolve('./modules/paapi.js');
const nodeModules = path.resolve('./node_modules');

return Object.assign(libraries, {
core: {
name: 'chunk-core',
test: (module) => {
return module.resource?.startsWith(core) || module.resource?.startsWith(nodeModules);
}
},
paapi: {
// fledgeForGpt imports paapi to keep backwards compat for NPM consumers
// this makes the paapi module its own chunk, pulled in by both paapi and fledgeForGpt entry points,
// to avoid duplication
// TODO: remove this in prebid 9
name: 'chunk-paapi',
test: (module) => {
return module.resource === paapiMod;
}
}
}, {
default: false,
defaultVendors: false
})
});
})()
}
},
Expand Down

0 comments on commit c27f64b

Please sign in to comment.