From 8f2d86d18f48ae6becbe5e7d19010a725fd17130 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Tue, 30 Apr 2024 10:59:19 -0700 Subject: [PATCH] Build system: fix standalone debugging & inclusion of node dependencies (#11375) --- gulpfile.js | 87 ++++++++++++++++++++++++-------------------- webpack.conf.js | 10 ----- webpack.debugging.js | 30 +++++++++++++++ 3 files changed, 77 insertions(+), 50 deletions(-) create mode 100644 webpack.debugging.js diff --git a/gulpfile.js b/gulpfile.js index 4dbd92587fe..86c1b7fe509 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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'); @@ -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; } @@ -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); diff --git a/webpack.conf.js b/webpack.conf.js index c934b09d439..1035e985b22 100644 --- a/webpack.conf.js +++ b/webpack.conf.js @@ -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()); @@ -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) => { diff --git a/webpack.debugging.js b/webpack.debugging.js new file mode 100644 index 00000000000..3952649c557 --- /dev/null +++ b/webpack.debugging.js @@ -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' + } + ] + }, + ] + } +};