Skip to content

Commit f3ce25d

Browse files
authored
Build system: add option to generate source maps for production builds (prebid#8220)
1 parent 76d29fd commit f3ce25d

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

gulpfile.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ function makeDevpackPkg() {
134134

135135
function makeWebpackPkg() {
136136
var cloned = _.cloneDeep(webpackConfig);
137-
delete cloned.devtool;
137+
if (!argv.sourceMaps) {
138+
delete cloned.devtool;
139+
}
138140

139141
var externalModules = helpers.getArgModules();
140142

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

152+
function addBanner() {
153+
const sm = argv.sourceMaps;
154+
155+
return gulp.src(['build/dist/prebid-core.js'])
156+
.pipe(gulpif(sm, sourcemaps.init({loadMaps: true})))
157+
.pipe(header(banner, {prebid}))
158+
.pipe(gulpif(sm, sourcemaps.write('.')))
159+
.pipe(gulp.dest('build/dist'))
160+
}
161+
151162
function getModulesListToAddInBanner(modules) {
152163
return (modules.length > 0) ? modules.join(', ') : 'All available modules in current version.';
153164
}
@@ -172,6 +183,7 @@ function nodeBundle(modules) {
172183
function bundle(dev, moduleArr) {
173184
var modules = moduleArr || helpers.getArgModules();
174185
var allModules = helpers.getModuleNames(modules);
186+
const sm = dev || argv.sourceMaps;
175187

176188
if (modules.length === 0) {
177189
modules = allModules.filter(module => explicitModules.indexOf(module) === -1);
@@ -203,13 +215,13 @@ function bundle(dev, moduleArr) {
203215
)
204216
// Need to uodate the "Modules: ..." section in comment with the current modules list
205217
.pipe(replace(/(Modules: )(.*?)(\*\/)/, ('$1' + getModulesListToAddInBanner(helpers.getArgModules()) + ' $3')))
206-
.pipe(gulpif(dev, sourcemaps.init({ loadMaps: true })))
218+
.pipe(gulpif(sm, sourcemaps.init({ loadMaps: true })))
207219
.pipe(concat(outputFileName))
208220
.pipe(gulpif(!argv.manualEnable, footer('\n<%= global %>.processQueue();', {
209221
global: prebid.globalVarName
210222
}
211223
)))
212-
.pipe(gulpif(dev, sourcemaps.write('.')));
224+
.pipe(gulpif(sm, sourcemaps.write('.')));
213225
}
214226

215227
// Run the unit tests.
@@ -398,7 +410,7 @@ gulp.task(clean);
398410
gulp.task(escapePostbidConfig);
399411

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

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

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

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

0 commit comments

Comments
 (0)