Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to webpack 4 #4112

Closed
wants to merge 16 commits into from
Closed
3 changes: 2 additions & 1 deletion .babelrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ module.exports = {
"ie >= 10",
"ios >= 8"
]
}
},
modules: 'commonjs' //This causes Babel to transpile ES modules into CJS modules before Webpack sees them, which prevents Webpack from creating getters, which fixes Sinon.(Ref: https://github.com/webpack/webpack/issues/6979)
}
]
],
Expand Down
2 changes: 1 addition & 1 deletion gulpHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module.exports = {
nameModules: function(externalModules) {
var modules = this.getModules(externalModules);
return through.obj(function(file, enc, done) {
file.named = modules[file.path] ? modules[file.path] : 'prebid';
file.named = modules[file.path] ? modules[file.path] : 'prebid-core';
this.push(file);
done();
})
Expand Down
51 changes: 24 additions & 27 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var shell = require('gulp-shell');
var eslint = require('gulp-eslint');
var gulpif = require('gulp-if');
var sourcemaps = require('gulp-sourcemaps');
var filter = require('gulp-filter');
var through = require('through2');
var fs = require('fs');
var jsEscape = require('gulp-js-escape');
Expand Down Expand Up @@ -66,13 +67,13 @@ function lint(done) {
}
const isFixed = function(file) {
return file.eslint != null && file.eslint.fixed;
}
};
return gulp.src(['src/**/*.js', 'modules/**/*.js', 'test/**/*.js'], {base: './'})
.pipe(gulpif(argv.nolintfix, eslint(), eslint({fix: true})))
.pipe(eslint.format('stylish'))
.pipe(eslint.failAfterError())
.pipe(gulpif(isFixed, gulp.dest('./')));
};
}

// View the code coverage report in the browser.
function viewCoverage(done) {
Expand All @@ -86,7 +87,7 @@ function viewCoverage(done) {
});
opens('http://' + mylocalhost + ':' + coveragePort);
done();
};
}

viewCoverage.displayName = 'view-coverage';

Expand Down Expand Up @@ -115,36 +116,32 @@ function watch(done) {
done();
};

function makeDevpackPkg() {
function makeWebpackPkg(dev) {
var cloned = _.cloneDeep(webpackConfig);
cloned.devtool = 'source-map';
var externalModules = helpers.getArgModules();

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());
}

function makeWebpackPkg() {
var cloned = _.cloneDeep(webpackConfig);
delete cloned.devtool;

var externalModules = helpers.getArgModules();
if (!dev) {
delete cloned.devtool;
cloned.mode = 'production';
}

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

var coreFilter = filter(['**/prebid-core.js', '**/prebid-shared.js'], {restore: true});

return gulp.src([].concat(moduleSources, analyticsSources, 'src/prebid.js'))
.pipe(helpers.nameModules(externalModules))
.pipe(webpackStream(cloned, webpack))
.pipe(uglify())
.pipe(gulpif(file => file.basename === 'prebid-core.js', header(banner, { prebid: prebid })))
.pipe(gulp.dest('build/dist'));
.pipe(coreFilter)
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(concat('prebid-core.js'))
.pipe(sourcemaps.write())
.pipe(coreFilter.restore)
.pipe(gulpif(!dev, uglify()))
.pipe(gulpif(file => (!dev && file.basename === 'prebid-core.js'), header(banner, { prebid: prebid })))
.pipe(gulp.dest(dev ? 'build/dev' : 'build/dist'))
.pipe(connect.reload());
}

function gulpBundle(dev) {
Expand Down Expand Up @@ -202,7 +199,7 @@ function bundle(dev, moduleArr) {
global: prebid.globalVarName
}
)))
.pipe(gulpif(dev, sourcemaps.write('.')));
.pipe(gulpif(dev, sourcemaps.write()));
}

// Run the unit tests.
Expand Down Expand Up @@ -298,8 +295,8 @@ 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-dev', gulp.series(makeWebpackPkg.bind(null, true), gulpBundle.bind(null, true)));
gulp.task('build-bundle-prod', gulp.series(makeWebpackPkg.bind(null, false), gulpBundle.bind(null, false)));

// public tasks (dependencies are needed for each task since they can be ran on their own)
gulp.task('test', gulp.series(clean, lint, test));
Expand All @@ -313,7 +310,7 @@ gulp.task('build', gulp.series(clean, 'build-bundle-prod'));
gulp.task('build-postbid', gulp.series(escapePostbidConfig, buildPostbid));

gulp.task('serve', gulp.series(clean, lint, gulp.parallel('build-bundle-dev', watch, test)));
gulp.task('default', gulp.series(clean, makeWebpackPkg));
gulp.task('default', gulp.series(clean, makeWebpackPkg.bind(null, true)));

gulp.task('e2e-test', gulp.series(clean, setupE2e, gulp.parallel('build-bundle-dev', watch), test))
// other tasks
Expand Down
4 changes: 2 additions & 2 deletions karma.conf.maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function newWebpackConfig(codeCoverage) {
// Make a clone here because we plan on mutating this object, and don't want parallel tasks to trample each other.
var webpackConfig = _.cloneDeep(webpackConf);

// remove optimize plugin for tests
// remove plugin for tests
webpackConfig.plugins.pop()

webpackConfig.optimization = {};
webpackConfig.devtool = 'inline-source-map';

if (codeCoverage) {
Expand Down
Loading