当我在gitbash中运行命令'gulp'时,会显示代码的最后一行的错误: 抛出新的错误('任务需要一个字符串的名称');
错误:任务需要名称为字符串
"use strict";
var gulp = require('gulp');
var connect = require('gulp-connect'); // Runs a local dev server
var open = require('gulp-open'); // Open a URL in a web browser
var config = {
port: 9005,
devBaseUrl: 'http://localhost',
paths: {
html: './src/*.html',
dist: './dist'
}
};
gulp.task(connect, function(){
connect.server({
root: '[dist]',
port: config.port,
base: config.devBaseUrl,
livereload: true
});
});
gulp.task(open,['connect'], function(){
gulp.src('dist/index.html')
.pipe(open({ url:config.devBaseUrl + ':' + config.port + '/'}));
});
gulp.task(html,function(){
gulp.src(config.paths.html)
.pipe(gulp.src(config.paths.dist))
.pipe(connect.reload());
});
gulp.task('watch', function(){
gulp.watch(config.paths.html, ['html']);
});
gulp.task('default', ['html', 'open', 'watch']);
答案 0 :(得分:0)
定义任务时,第一个参数应该是字符串。
gulp.task('connect', function () {
.....
})
这是更正的文件:
var gulp = require('gulp');
var connect = require('gulp-connect'); // Runs a local dev server
var open = require('gulp-open'); // Open a URL in a web browser
var config = {
port: 9005,
devBaseUrl: 'http://localhost',
paths: {
html: './src/*.html',
dist: './dist'
}
};
gulp.task('connect', function(){
connect.server({
root: '[dist]',
port: config.port,
base: config.devBaseUrl,
livereload: true
});
});
gulp.task('open',['connect'], function(){
gulp.src('dist/index.html')
.pipe(open({ url:config.devBaseUrl + ':' + config.port + '/'}));
});
gulp.task('html',function(){
gulp.src(config.paths.html)
.pipe(gulp.src(config.paths.dist))
.pipe(connect.reload());
});
gulp.task('watch', function(){
gulp.watch(config.paths.html, ['html']);
});
gulp.task('default', ['html', 'open', 'watch']);