Reputation: 743
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
});
});
Upvotes: 22
Views: 24124
Reputation: 913
'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']));
'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']));
Upvotes: 0
Reputation: 740
I had a similar issue, and this is 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 :)
Upvotes: 1
Reputation: 1424
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.
Upvotes: 30
Reputation: 3905
Create a default task and add tasks you would like to run by default:
gulp.task("default", function () {
gulp.start("serve");
});
Upvotes: 2
Reputation: 438
Please include this in your gulp file.
gulp.task('default', ['serve']);
Hope this might help.
Upvotes: 4