Skip to content

Commit

Permalink
Build system: fix standalone debugging & inclusion of node dependenci…
Browse files Browse the repository at this point in the history
…es (prebid#11375)
  • Loading branch information
dgirardi authored and f.caspar committed May 14, 2024
1 parent 0b5f521 commit d9b3207
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 50 deletions.
87 changes: 47 additions & 40 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var webpackStream = require('webpack-stream');
var gulpClean = require('gulp-clean');
var opens = require('opn');
var webpackConfig = require('./webpack.conf.js');
const standaloneDebuggingConfig = require('./webpack.debugging.js');
var helpers = require('./gulpHelpers.js');
var concat = require('gulp-concat');
var replace = require('gulp-replace');
Expand Down Expand Up @@ -127,35 +128,56 @@ function viewReview(done) {

viewReview.displayName = 'view-review';

function makeDevpackPkg() {
var cloned = _.cloneDeep(webpackConfig);
Object.assign(cloned, {
devtool: 'source-map',
mode: 'development'
})
function makeVerbose(config = webpackConfig) {
return _.merge({}, config, {
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: false,
format: {
comments: 'all'
}
},
extractComments: false,
}),
],
}
});
}

const babelConfig = require('./babelConfig.js')({disableFeatures: helpers.getDisabledFeatures(), prebidDistUrlBase: argv.distUrlBase || '/build/dev/'});
function makeDevpackPkg(config = webpackConfig) {
return function() {
var cloned = _.cloneDeep(config);
Object.assign(cloned, {
devtool: 'source-map',
mode: 'development'
})

const babelConfig = require('./babelConfig.js')({disableFeatures: helpers.getDisabledFeatures(), prebidDistUrlBase: argv.distUrlBase || '/build/dev/'});

// update babel config to set local dist url
cloned.module.rules
.flatMap((rule) => rule.use)
.filter((use) => use.loader === 'babel-loader')
.forEach((use) => use.options = Object.assign({}, use.options, babelConfig));
// update babel config to set local dist url
cloned.module.rules
.flatMap((rule) => rule.use)
.filter((use) => use.loader === 'babel-loader')
.forEach((use) => use.options = Object.assign({}, use.options, babelConfig));

var externalModules = helpers.getArgModules();
var externalModules = helpers.getArgModules();

const analyticsSources = helpers.getAnalyticsSources();
const moduleSources = helpers.getModulePaths(externalModules);
const analyticsSources = helpers.getAnalyticsSources();
const moduleSources = helpers.getModulePaths(externalModules);

return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(gulp.dest('build/dev'))
.pipe(connect.reload());
}
}

function makeWebpackPkg(extraConfig = {}) {
var cloned = _.merge(_.cloneDeep(webpackConfig), extraConfig);
function makeWebpackPkg(config = webpackConfig) {
var cloned = _.cloneDeep(config)
if (!argv.sourceMaps) {
delete cloned.devtool;
}
Expand Down Expand Up @@ -495,26 +517,11 @@ gulp.task(escapePostbidConfig);
gulp.task('build-creative-dev', gulp.series(buildCreative(argv.creativeDev ? 'development' : 'production'), updateCreativeRenderers));
gulp.task('build-creative-prod', gulp.series(buildCreative(), updateCreativeRenderers));

gulp.task('build-bundle-dev', gulp.series('build-creative-dev', makeDevpackPkg, gulpBundle.bind(null, true)));
gulp.task('build-bundle-prod', gulp.series('build-creative-prod', makeWebpackPkg(), gulpBundle.bind(null, false)));
gulp.task('build-bundle-dev', gulp.series('build-creative-dev', makeDevpackPkg(standaloneDebuggingConfig), makeDevpackPkg(), gulpBundle.bind(null, true)));
gulp.task('build-bundle-prod', gulp.series('build-creative-prod', makeWebpackPkg(standaloneDebuggingConfig), makeWebpackPkg(), gulpBundle.bind(null, false)));
// build-bundle-verbose - prod bundle except names and comments are preserved. Use this to see the effects
// of dead code elimination.
gulp.task('build-bundle-verbose', gulp.series(makeWebpackPkg({
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
mangle: false,
format: {
comments: 'all'
}
},
extractComments: false,
}),
],
}
}), gulpBundle.bind(null, false)));
gulp.task('build-bundle-verbose', gulp.series('build-creative-dev', makeWebpackPkg(makeVerbose(standaloneDebuggingConfig)), makeWebpackPkg(makeVerbose()), gulpBundle.bind(null, true)));

// public tasks (dependencies are needed for each task since they can be ran on their own)
gulp.task('test-only', test);
Expand Down
10 changes: 0 additions & 10 deletions webpack.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ module.exports = {
'prebid-core': {
import: './src/prebid.js'
},
'debugging-standalone': {
import: './modules/debugging/standalone.js'
}
};
const selectedModules = new Set(helpers.getArgModules());

Expand Down Expand Up @@ -130,15 +127,8 @@ module.exports = {
);
const core = path.resolve('./src');
const paapiMod = path.resolve('./modules/paapi.js');
const nodeModules = path.resolve('./node_modules');

return Object.assign(libraries, {
common_deps: {
name: 'common_deps',
test(module) {
return module.resource && module.resource.startsWith(nodeModules);
}
},
core: {
name: 'chunk-core',
test: (module) => {
Expand Down
30 changes: 30 additions & 0 deletions webpack.debugging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var path = require('path');

module.exports = {
mode: 'production',
devtool: 'source-map',
resolve: {
modules: [
path.resolve('.'),
'node_modules'
],
},
entry: {
'debugging-standalone': {
import: './modules/debugging/standalone.js',
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: path.resolve('./node_modules'), // required to prevent loader from choking non-Prebid.js node_modules
use: [
{
loader: 'babel-loader'
}
]
},
]
}
};

0 comments on commit d9b3207

Please sign in to comment.