Gulp TypeError:dest.on不是函数

时间:2016-04-28 07:34:19

标签: javascript gulp webpack require

我正在尝试使用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

enter image description here

这是文件夹目录:

enter image description here

1 个答案:

答案 0 :(得分:9)

发生错误是因为webpack与gulp流本身不起作用。当然,webpack()返回的对象并不包含特定于gulp的dest.on

使用gulp-webpack或按照官方文档了解如何使用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/'));
});