hard-source-webpack-plugin
hard-source-webpack-plugin copied to clipboard
Errors are not shown with gulp + webpack-stream
If I run webpack with HardSourcePlugin through gulp using webpack-stream ( https://github.com/shama/webpack-stream) , I don't see any errors. Just build failure.
Without HardSourcePlugin the errors are displayed properly.
Maybe this will help you: webpack-stream didn't cut it for us for multiple reasons, including what you're talking about. Eventually, I wrote our own script to run webpack through gulp, like this:
gulp.task('build-webpack', done => {
webpackAsync('webpack.config.js', done);
});
function webpackAsync (config, entry, callback) {
config = require(path.join(configsLocation, config));
webpack(config, (error, stats) => {
if (hasErrors(stats)) {
// Break Gulp execution:
process.exit(1);
// Or return the error to Gulp (you can choose)
// if (typeof callback === 'function') {
// callback(new Error('Webpack error (see above).');
// }
} else if (typeof callback === 'function') {
callback();
}
});
}
* We have multiple builds, hence requireing the build from within webpackAsync and not from the Gulp task.
I’ll try this. Thanks. Any reason you don’t return Promise?
You mean like so?
gulp.task('build-webpack', () => {
return webpackAsync('webpack.config.js'); // (considering webpackAsync return a promise of course)
});
Yes, that way you don’t need done argument. Btw instead of require you could also do it async with fse.read (fs-extra) or util.promisify. It will make build faster ;)
What do you mean will make build faster?
Asynchronous operation allows other IO operation to be done at the same time.
@stereokai Do you know how to make multiple output directories using your method ? Currently I have:
gulp.src("*")
.pipe(webpackStream(require(webpackConfig), webpack))
.pipe(gulp.dest("out1"))
.pipe(gulp.dest("out2"))
I can do manually build + copy, but using gulp.dest is much nicer.