hard-source-webpack-plugin icon indicating copy to clipboard operation
hard-source-webpack-plugin copied to clipboard

Errors are not shown with gulp + webpack-stream

Open NN--- opened this issue 7 years ago • 7 comments

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.

NN--- avatar Mar 22 '18 07:03 NN---

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.

stereokai avatar Mar 22 '18 15:03 stereokai

I’ll try this. Thanks. Any reason you don’t return Promise?

NN--- avatar Mar 22 '18 15:03 NN---

You mean like so?

gulp.task('build-webpack', () => {
  return webpackAsync('webpack.config.js'); // (considering webpackAsync return a promise of course)
});

stereokai avatar Mar 22 '18 16:03 stereokai

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

NN--- avatar Mar 22 '18 16:03 NN---

What do you mean will make build faster?

stereokai avatar Mar 22 '18 17:03 stereokai

Asynchronous operation allows other IO operation to be done at the same time.

NN--- avatar Mar 22 '18 17:03 NN---

@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.

NN--- avatar Mar 22 '18 19:03 NN---