S
S
Samad_Samadovic2022-03-31 14:11:50
gulp.js
Samad_Samadovic, 2022-03-31 14:11:50

Hello, when writing a gulp command, it says that there are no tasks, what is the error?

When writing the gulp command in the terminal, an error occurs:
Task never defined: default
Here is the gulpfile.js itself:

const gulp_run = require("gulp"),
gulpsass = require("gulp-sass"),
watch = require("gulp-watch");
const { clean } = require("semver");

const path ={
    templates:{
        src:"src/templates/*.html",
        dest:"build",
        watch:"src/templates/**/*.html",
    },
    styles:{
        src:"src/styles/main.scss",
        dest:"build/assets/css",
        watch:"src/styles/parsials/**/*.scss",
    },
    fonts:{
        src:"src/fonts/*",
        dest:"build",
        watch:"src/fonts/**/*",
    },
    images:{
        src:"src/images/*",
        dest:"build",
        watch:"src/images/**/*",
    },
}

gulp.task('templates', function(){
    return gulp
    .src(path.templates.src)
    .pipe(gulp.dest.path.templates.dest)
    .on('end', browserSync.reload);
})

gulp.task('styles', function(){
    return gulp
    .src(path.styles.src)
    .pipe(gulp.dest.path.styles.dest)
    .pipe(sass())
    .on('end', browserSync.reload);
})

gulp.task('fonts', function(){
    return gulp
    .src(path.fonts.src)
    .pipe(gulp.dest.path.fots.dest)
    .on('end', browserSync.reload);
})

gulp.task('images', function(){
    return gulp
    .src(path.images.src)
    .pipe(gulp.dest.path.images.dest)
    .on('end', browserSync.reload);
})

gulp.task('watch', function(){
    return new Promise((res,rej)=>{watch(path.templates.watch,gulp.series("templates"));
    watch(path.styles.watch,gulp.series("styles"));
    watch(path.images.watch,gulp.series("images"));
});
});

gulp.task('clean', function(){
    return gulp.src('./build/*',{read: false}).pipe(clean());
});

gulp.task('serve', function(){
    return new Promise((res,rej)=>{
        browserSync.init({
            server: './build/', tunnel: true, port: 4200,
        });
        res();
});
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iBird Rose, 2022-03-31
@Samad_Samadovic

when writing a command, just gulp - it looks for the default task. you don't have it
gulp.task('default'

A
Alexander Viktorovich, 2022-04-01
@shotlandec1980

like this, didn't check.
https://gulpjs.com/docs/en/getting-started/creatin...
install dependenciesnpm install gulp sass browser-sync del --save-dev

// gulpfile.js
'use strict';

const { src, dest, lastRun, watch, series, parallel } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const browserSync = require('browser-sync').create();
const del = require('del');

const path = {
  templates: {
    src: 'src/templates/*.html',
    dest: 'build',
    watching: 'src/templates/**/*.html',
  },
  styles: {
    src: 'src/styles/main.scss',
    dest: 'build/assets/css',
    watching: 'src/styles/parsials/**/*.scss',
  },
  fonts: {
    src: 'src/fonts/*',
    dest: 'build',
    watching: 'src/fonts/**/*',
  },
  images: {
    src: 'src/images/*',
    dest: 'build',
    watching: 'src/images/**/*',
  },
};

function cleanup() {
  return del([path.build]);
}

function server() {
  browserSync.init({
    server: {
      baseDir: './build/',
    },
    port: 3004,
    open: false,
    notify: true,
    browser: 'default',
    online: true,
    // logLevel: 'debug',
  });
}

function templates() {
  return src(path.templates.src)
    .pipe(dest(path.templates.dest))
    .on('end', browserSync.reload);
}

function styles() {
  return src(path.styles.src)
    .pipe(sass.sync())
    .pipe(dest(path.styles.dest))
    .on('end', browserSync.reload);
}

function watching() {
  watch(path.templates.watching, series('templates'));
  watch(path.styles.watching, series('styles'));
  watch(path.images.watching, series('images'));
}

exports.default = series(templates, styles);

exports.development = series(cleanup, exports.default, parallel(watching, server));

// package.json добавить 
.....
"scripts": {
    "start": "gulp development",
},
.......

launchnpm run start

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question