Task "default" is not in your gulpfile
Asked Answered
A

5

22

I run gulp in my console I got this error:

Task 'default' is not in your gulpfile

My gulpfile looks just fine:

var gulp = require('gulp'),
    LiveServer = require('gulp-live-server'),
    browserSync = require('browser-sync');

gulp.task('live-server', function () {
    var server = new LiveServer('server/main.js');
    server.start();
});

gulp.task('serve', ['live-server'], function () {
    browserSync.init(null, {
        proxy: "http://localhost:3000",
        port: 9001
    });
});
Amytal answered 26/12, 2016 at 10:41 Comment(0)
D
30

When you just run gulp in your console it will look for a default task to run. You only defined live-server and serve as tasks.

To solve define a default task, you can add the task you actually want to run as the dependency like so:

gulp.task( 'default', [ 'serve' ] )

Now if you run gulp it will run the default task which in turn runs the serve task. Alternatively you can just run gulp serve and it will work as well.

Darrin answered 26/12, 2016 at 10:50 Comment(1)
Very usefull plugin if you have lots of task in your config file is gulp-help, that will serve as your helper when you type plain "gulp" for example, listing you all available commands.Maryannemarybella
Y
4

Please include this in your gulp file.

gulp.task('default', ['serve']);

Hope this might help.

Yukoyukon answered 26/12, 2016 at 10:49 Comment(0)
M
2

Create a default task and add tasks you would like to run by default:

gulp.task("default", function () {
  gulp.start("serve");
});
Mandimandible answered 26/12, 2016 at 10:53 Comment(0)
M
1

I had a similar issue, and this is my gulp file

My gulp file

Instead of having a 'default' task, what i do is directly calling the 'serve' task.

In cmd -> gulp serve

By directly calling the serve, it would call the browser-sync task for me.

Hope this would be helpful for someone :)

Melanesian answered 16/11, 2017 at 5:6 Comment(0)
R
0

Here was mine before...

'use strict';

var gulp = require('gulp');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var uglify = require('gulp-uglify');
var merge = require('merge-stream');
var bundleConfig = require('./bundleconfig.json');

const REGEX = {
    css: /\.css$/,
    js: /\.js$/
};

gulp.task('min:js', async function () {
    merge(getBundles(REGEX.js).map(bundle => {
        return gulp.src(bundle.inputFiles, { base: '.' })
            .pipe(concat(bundle.outputFileName))
            .pipe(uglify())
            .pipe(gulp.dest('.'));
    }))
});

gulp.task('min:css', async function () {
    merge(getBundles(REGEX.css).map(bundle => {
        return gulp.src(bundle.inputFiles, { base: '.' })
            .pipe(concat(bundle.outputFileName))
            .pipe(cssmin())
            .pipe(gulp.dest('.'));
    }))
});

const getBundles = (regexPattern) => {
    return bundleConfig.filter(bundle => {
        return regexPattern.test(bundle.outputFileName);
    });
};

gulp.task('minify', gulp.series(['min:js', 'min:css']));

And then after, literally just had to change the last line to 'default' smh

'use strict';

var gulp = require('gulp');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var uglify = require('gulp-uglify');
var merge = require('merge-stream');
var bundleConfig = require('./bundleconfig.json');

const REGEX = {
    css: /\.css$/,
    js: /\.js$/
};

gulp.task('min:js', async function () {
    merge(getBundles(REGEX.js).map(bundle => {
        return gulp.src(bundle.inputFiles, { base: '.' })
            .pipe(concat(bundle.outputFileName))
            .pipe(uglify())
            .pipe(gulp.dest('.'));
    }))
});

gulp.task('min:css', async function () {
    merge(getBundles(REGEX.css).map(bundle => {
        return gulp.src(bundle.inputFiles, { base: '.' })
            .pipe(concat(bundle.outputFileName))
            .pipe(cssmin())
            .pipe(gulp.dest('.'));
    }))
});

const getBundles = (regexPattern) => {
    return bundleConfig.filter(bundle => {
        return regexPattern.test(bundle.outputFileName);
    });
};

gulp.task('default', gulp.series(['min:js', 'min:css']));
Rabassa answered 14/11, 2021 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.