Gulp TypeError: dest.on is not a function

Gulp TypeError: dest.on is not a function

我正在尝试生成一个包含 Gulp 任务的 bundle.js 文件

var gulp = require('gulp'),
    gutil = require('gulp-util'),
    wrench = require('wrench'),
    conf = require('./webpack.config'),
    webpack = require('webpack'),
    WebpackDevServer = require('webpack-dev-server');

// Webpack
gulp.task('wp', function() {
  return gulp.src('./assets/scripts/entry.js')
    .pipe(webpack(conf))
    .pipe(gulp.dest('./assets/build1'));
});

但是,当我尝试 运行 时得到 TypeError: dest.on is not a function

文件夹目录如下:

错误的发生是因为 webpack 本身不支持 gulp 流。 webpack() 返回的对象自然不包括 dest.on 特定于 gulp.

或者使用gulp-webpack or follow the official docs on how to use webpack with gulp

示例代码直接取自使用webpack-stream:

的官方文档
var gulp = require('gulp');
var webpack = require('webpack-stream');

gulp.task('default', function() {
  return gulp.src('src/entry.js')
    .pipe(webpack())
    .pipe(gulp.dest('dist/'));
});