Javascript Gulp TypeError:dest.on 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36908177/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gulp TypeError: dest.on is not a function
提问by McBooley
I'm trying to generate a bundle.js file with a Gulp task
我正在尝试使用 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'));
});
However, I get TypeError: dest.on is not a function
when I try to run it:
但是,TypeError: dest.on is not a function
当我尝试运行它时,我得到了:
Here's the folder directory:
这是文件夹目录:
回答by marvinhagemeister
The error occurs because webpack doesn't work natively with gulp streams. Naturally the returned object by webpack()
doesn't include dest.on
which is specific to gulp.
发生该错误是因为 webpack 本身无法与 gulp 流一起使用。自然地,返回的对象 bywebpack()
不包括dest.on
特定于 gulp 的对象。
Either use gulp-webpackor follow the official docs on how to use webpack with gulp
使用gulp-webpack或按照官方文档了解如何使用webpack 和 gulp
Sample code taken straight out of the official docs which uses webpack-stream
:
直接从官方文档中提取的示例代码使用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/'));
});