D
D
Dmitry Katyushin2015-04-12 09:30:28
JavaScript
Dmitry Katyushin, 2015-04-12 09:30:28

Gulp throws an error, can you help?

Hello, I understand that all errors are indicated in the console, but it seems to me that something is wrong, it seems that I did everything right, please help, I have already suffered so much with this Gulp.

'use strict';

var gulp = require('gulp'),
    watch = require('gulp-watch'),
    prefixer = require('gulp-autoprefixer'),
    uglify = require('gulp-uglify'),
    sass = require('gulp-sass'),
    concat = require('gulp-concat'),
    rigger = require('gulp-rigger'),
    csso = require('gulp-csso'),
    imagemin = require('gulp-imagemin'),
    pngquant = require('imagemin-pngquant'),
    concatCss = require('gulp-concat-css'),
    browserSync = require("browser-sync"),
    htmlmin = require('gulp-htmlmin'),
    reload = browserSync.reload;

var path = {
    dist: {
        html: 'dist/',
        js: 'dist/js/',
        css: 'dist/css/',
        img: 'dist/img/',
        fonts: 'dist/fonts/'
    },
    assets: {
        html: 'assets/*.html',
        js: 'assets/js/*.js',
        css: 'assets/css/main.scss',
        img: 'assets/img/**/*.*',
        fonts: 'assets/fonts/*.*'
    },
    watch: {
        html: 'assets/**/*.html',
        js: 'assets/js/**/*.js',
        css: 'assets/css/*.scss',
        img: 'assets/img/**/*.*',
        fonts: 'assets/fonts/*.*'
    },
};

var config = {
    server: {
        baseDir: "./dist"
    },
    tunnel: true,
    host: 'localhost',
    port: 9000,
    logPrefix: "Frontend"
};

gulp.task('webserver', function () {
    browserSync(config);
});

gulp.task('html:dist', function () {
    gulp.assets(path.assets.html) 
        .pipe(rigger())
        .pipe(htmlmin({collapseWhitespace: true}))
        .pipe(gulp.dest(path.dist.html))
        .pipe(reload({stream: true}));
});

gulp.task('js:dist', function () {
    gulp.assets(path.assets.js) 
        .pipe(rigger())
        .pipe(concat('main.js'))
        .pipe(uglify()) 
        .pipe(gulp.dest(path.dist.js))
        .pipe(reload({stream: true}));
});

gulp.task('css:dist', function () {
    gulp.assets(path.assets.css) 
        .pipe(sass({
            includePaths: ['assets/css/'],
            outputStyle: 'compressed',
            sourceMap: true,
            errLogToConsole: true
        }))
        .pipe(prefixer())
        .pipe(concatCss("main.css"))
        .pipe(csso())
        .pipe(gulp.dest(path.dist.css))
        .pipe(reload({stream: true}));
});

gulp.task('img:dist', function () {
    gulp.assets(path.assets.img) 
        .pipe(imagemin({
            progressive: true,
            svgoPlugins: [{removeViewBox: false}],
            use: [pngquant()],
            interlaced: true
        }))
        .pipe(gulp.dest(path.dist.img))
        .pipe(reload({stream: true}));
});

gulp.task('fonts:dist', function() {
    gulp.assets(path.assets.fonts)
        .pipe(gulp.dest(path.dist.fonts))
});

gulp.task('dist', [
    'html:dist',
    'js:dist',
    'css:dist',
    'fonts:dist',
    'img:dist'
]);


gulp.task('watch', function(){
    watch([path.watch.html], function(event, cb) {
        gulp.start('html:dist');
    });
    watch([path.watch.css], function(event, cb) {
        gulp.start('css:dist');
    });
    watch([path.watch.js], function(event, cb) {
        gulp.start('js:dist');
    });
    watch([path.watch.img], function(event, cb) {
        gulp.start('img:dist');
    });
    watch([path.watch.fonts], function(event, cb) {
        gulp.start('fonts:dist');
    });
});


gulp.task('default', ['dist', 'webserver', 'watch']);

Gives this 86f00c55846544e485ab25886cc81981.png
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan, 2015-04-12
@A1ike

Change everywhere gulp.assets()togulp.src()

M
Maxim, 2015-04-12
Antonikhin @STJ

As far as I understand, you need to look at the usage example https://www.npmjs.com/package/gulp-assets , but you don't have it in modules.

gulp.src("./src/*.html")
    .pipe(assets({
        js: true,
        css: false
    }))
    .pipe(gulp.dest("./dist"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question