Skip to content

Commit

Permalink
Build system: add option to generate source maps for production builds (
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Mar 31, 2022
1 parent 76d29fd commit f3ce25d
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ function makeDevpackPkg() {

function makeWebpackPkg() {
var cloned = _.cloneDeep(webpackConfig);
delete cloned.devtool;
if (!argv.sourceMaps) {
delete cloned.devtool;
}

var externalModules = helpers.getArgModules();

Expand All @@ -144,10 +146,19 @@ function makeWebpackPkg() {
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(gulp.dest('build/dist'));
}

function addBanner() {
const sm = argv.sourceMaps;

return gulp.src(['build/dist/prebid-core.js'])
.pipe(gulpif(sm, sourcemaps.init({loadMaps: true})))
.pipe(header(banner, {prebid}))
.pipe(gulpif(sm, sourcemaps.write('.')))
.pipe(gulp.dest('build/dist'))
}

function getModulesListToAddInBanner(modules) {
return (modules.length > 0) ? modules.join(', ') : 'All available modules in current version.';
}
Expand All @@ -172,6 +183,7 @@ function nodeBundle(modules) {
function bundle(dev, moduleArr) {
var modules = moduleArr || helpers.getArgModules();
var allModules = helpers.getModuleNames(modules);
const sm = dev || argv.sourceMaps;

if (modules.length === 0) {
modules = allModules.filter(module => explicitModules.indexOf(module) === -1);
Expand Down Expand Up @@ -203,13 +215,13 @@ function bundle(dev, moduleArr) {
)
// Need to uodate the "Modules: ..." section in comment with the current modules list
.pipe(replace(/(Modules: )(.*?)(\*\/)/, ('$1' + getModulesListToAddInBanner(helpers.getArgModules()) + ' $3')))
.pipe(gulpif(dev, sourcemaps.init({ loadMaps: true })))
.pipe(gulpif(sm, sourcemaps.init({ loadMaps: true })))
.pipe(concat(outputFileName))
.pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', {
global: prebid.globalVarName
}
)))
.pipe(gulpif(dev, sourcemaps.write('.')));
.pipe(gulpif(sm, sourcemaps.write('.')));
}

// Run the unit tests.
Expand Down Expand Up @@ -398,7 +410,7 @@ gulp.task(clean);
gulp.task(escapePostbidConfig);

gulp.task('build-bundle-dev', gulp.series(makeDevpackPkg, gulpBundle.bind(null, true)));
gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg, gulpBundle.bind(null, false)));
gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg, addBanner, gulpBundle.bind(null, false)));

// public tasks (dependencies are needed for each task since they can be ran on their own)
gulp.task('test-only', test);
Expand All @@ -417,7 +429,7 @@ gulp.task('serve-fast', gulp.series(clean, gulp.parallel('build-bundle-dev', wat
gulp.task('serve-and-test', gulp.series(clean, gulp.parallel('build-bundle-dev', watchFast, testTaskMaker({watch: true}))));
gulp.task('serve-fake', gulp.series(clean, gulp.parallel('build-bundle-dev', watch), injectFakeServerEndpointDev, test, startFakeServer));

gulp.task('default', gulp.series(clean, makeWebpackPkg));
gulp.task('default', gulp.series(clean, 'build-bundle-prod'));

gulp.task('e2e-test', gulp.series(clean, setupE2e, gulp.parallel('build-bundle-prod', watch), injectFakeServerEndpoint, test));
// other tasks
Expand Down

0 comments on commit f3ce25d

Please sign in to comment.