Gulp 오류 : 감시 작업은 함수 여야합니다.
내 gulpfile은 다음과 같습니다.
// Modules & Plugins
var gulp = require('gulp');
var concat = require('gulp-concat');
var myth = require('gulp-myth');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var imagemin = require('gulp-imagemin');
// Styles Task
gulp.task('styles', function() {
return gulp.src('app/css/*.css')
.pipe(concat('all.css'))
.pipe(myth())
.pipe(gulp.dest('dist'));
});
// Scripts Task
gulp.task('scripts', function() {
return gulp.src('app/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('all.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
// Images Task
gulp.task('images', function() {
return gulp.src('app/img/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/img'));
});
// Watch Task
gulp.task('watch', function() {
gulp.watch('app/css/*.css', 'styles');
gulp.watch('app/js/*.js', 'scripts');
gulp.watch('app/img/*', 'images');
});
// Default Task
gulp.task('default', gulp.parallel('styles', 'scripts', 'images', 'watch'));
나는 실행하는 경우 images
, scripts
또는 css
혼자 작업을 그것을 작동합니다. 나는 return
작업 에 추가해야 했다-이것은 책에 없었지만 인터넷 검색은 이것이 필요하다는 것을 보여 주었다.
내가 가진 문제는 default
작업 오류입니다.
[18:41:59] Error: watching app/css/*.css: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)
at Gulp.watch (/media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/node_modules/gulp/index.js:28:11)
at /media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/gulpfile.js:36:10
at taskWrapper (/media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/node_modules/undertaker/lib/set-task.js:13:15)
at bound (domain.js:287:14)
at runBound (domain.js:300:12)
at asyncRunner (/media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/node_modules/async-done/index.js:36:18)
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
at Function.Module.runMain (module.js:444:11)
at startup (node.js:136:18)
return
워치 태스크 도 없기 때문이라고 생각합니다 . 또한 오류 메시지는 명확하지 않습니다-적어도 나에게는. 나는 return
마지막 후에 추가를 시도했지만 그것도 gulp.watch()
작동하지 않았습니다.
gulp 3.x에서는 다음 gulp.watch()
과 같이 작업 이름을 전달할 수 있습니다 .
gulp.task('watch', function() {
gulp.watch('app/css/*.css', ['styles']);
gulp.watch('app/js/*.js', ['scripts']);
gulp.watch('app/img/*', ['images']);
});
In gulp 4.x this is no longer the case. You have to pass a function. The customary way of doing this in gulp 4.x is to pass a gulp.series()
invocation with only one task name. This returns a function that only executes the specified task:
gulp.task('watch', function() {
gulp.watch('app/css/*.css', gulp.series('styles'));
gulp.watch('app/js/*.js', gulp.series('scripts'));
gulp.watch('app/img/*', gulp.series('images'));
});
GULP-V4.0
It is a bit late to answer this right now but still. I was stuck in this problem as well and this is how I got it working.
In detail analysis what I was doing wrong
- I forgot to call the reload function when the
watch
noticed some changes in my html files. - Since
fireUp
andKeepWatching
are blocking. They need to be started in parallel rather than serially. So I used the parallel function in the variable run.
thanks for all
gulp.task('watch', function(){
gulp.watch('app/sass/**/*.sass', gulp.series('sass'));
});
for version gulp 4.xx
It worked for me in Gulp 4.0
gulp.task('watch', function() {
gulp.watch('src/images/*.png', gulp.series('images'));
gulp.watch('src/js/*.js', gulp.series('js'));
gulp.watch('src/scss/*.scss', gulp.series('css'));
gulp.watch('src/html/*.html', gulp.series('html'));
});
//Check what worked for me
gulp.task('watch', function(){
gulp.watch('css/shop.css', gulp.series(['shop']));
});
참고URL : https://stackoverflow.com/questions/39665773/gulp-error-watch-task-has-to-be-a-function
'developer tip' 카테고리의 다른 글
파일 내용 내에서 문자열 바꾸기 (0) | 2020.09.15 |
---|---|
AJAX로 부트 스트랩 팝 오버 콘텐츠를로드합니다. (0) | 2020.09.15 |
UILabel 글꼴 크기? (0) | 2020.09.15 |
`react-native run-ios`가 오류를 반환합니다 : iPhone X 시뮬레이터를 찾을 수 없음 (0) | 2020.09.15 |
Scala에서 두 개 이상의 목록을 함께 압축 할 수 있습니까? (0) | 2020.09.15 |