Gulp “任务从未定义:默认值”

nnsrf1az  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(158)

如何解决我的问题?这里是我的gulpfile.js

const gulp = require('gulp');
const webp = require('gulp-webp');
const browserSync = require('browser-sync');

const origin = 'app';
const destination = 'app';

gulp.task('webp', () =>
gulp
.src(`${origin}/img/**`)
.pipe(webp())
.pipe(gulp.dest(`${destination}/img`))
);

gulp.task('live', function () {
gulp.watch('**/*.css').on('change', function () {
browserSync.reload();
 });
});

这是我的package.json

{
 "name": "gulp-browsersync",
 "version": "1.0.0",
 "description": "",
 "main": "index.js",
 "scripts": {
   "test": "echo \"Error: no test specified\" && exit 1",
   "watch": "node-sass --watch app/scss -o app/css"
 },
 "keywords": [],
 "author": "",
 "license": "ISC",
 "devDependencies": {
   "browser-sync": "^2.26.10",
   "gulp": "^4.0.2",
   "gulp-webp": "^4.0.1",
   "node-sass": "^4.14.1"
 },
 "dependencies": {}
 }

这是我的终端日志

[13:39:25] Using gulpfile ~\Desktop\gulp-browsersync-main\gulpfile.js
[13:39:25] Task never defined: default
[13:39:25] To list available tasks, try running: gulp --tasks
lvjbypge

lvjbypge1#

您需要从您的gulpfile.jsexports一个函数作为default
检查gulp-doc和创建任务
gulp需要一个函数来启动任务,你必须使用exports.default你主任务函数。如果你有多个任务,你需要使用seriesparallel
密码:

const gulp = require('gulp');
const webp = require('gulp-webp');
const browserSync = require('browser-sync');

const origin = 'app';
const destination = 'app';


function defaultTask(cb) {
    gulp.task('webp', () =>
        gulp
            .src(`${origin}/img/**`)
            .pipe(webp())
            .pipe(gulp.dest(`${destination}/img`))
    );

    gulp.task('live', function () {
        gulp.watch('**/*.css').on('change', function () {
            browserSync.reload();
        });
    });

    cb();
}

exports.default = defaultTask

相关问题