O
O
Oleg Sevoc2020-05-13 18:37:21
JavaScript
Oleg Sevoc, 2020-05-13 18:37:21

Why doesn't building to one file work on gulp?

Good day to all, I combine all js into one, I have a swiper folder there js files of the day, all js files are connected and wsiper also just doesn’t want to work, it doesn’t hit the console with an error, what could be the problem? And most importantly, it stores everything in common.js but does not overwrite it, but simply inserts copies, when you run gulp, another copy of js files appears!
5ebc12e3690a7375179986.jpeg

let gulp = require('gulp'),
    sass = require('gulp-sass'),
    browserSync = require('browser-sync'),
    uglify = require('gulp-uglify'),
    concat = require('gulp-concat'),
    rename = require('gulp-rename'),
    pug = require('gulp-pug'),
    imagemin = require('gulp-imagemin');

gulp.task('pug', function() {
    return gulp.src('app/*.pug')
        .pipe(pug({
            pretty: true
        }))
        .pipe(gulp.dest('app'))

})
gulp.task('imagemin', function() {
    return gulp.src('app/img/*')
        .pipe(imagemin())
        .pipe(gulp.dest('app/dist/images'))
});



gulp.task('scss', function() {
    return gulp.src('app/scss/**/*.scss')
        .pipe(sass({ outputStyle: 'compressed' }))
        .pipe(rename({ suffix: '.min' }))
        .pipe(gulp.dest('app/css'))
        .pipe(browserSync.reload({ stream: true }))
});


// Optimize images


gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: "app/"
        }
    });
});

gulp.task('html', function() {
    return gulp.src('app/*.html')
        .pipe(browserSync.reload({ stream: true }))

});


gulp.task('script', function() {
    return gulp.src('app/js/*.js')
        .pipe(browserSync.reload({ stream: true }))

});


gulp.task('js', function() {
    return gulp.src([
            'app/js/*.js',
            'node_modules/slick-carousel/slick/slick.js',
            'node_modules/magnific-popup/dist/jquery.magnific-popup.js'
        ])
        .pipe(concat('common.js'))
        .pipe(gulp.dest('app/js'))
        .pipe(browserSync.reload({ stream: true }))
});





gulp.task('watch', function() {
    gulp.watch('app/scss/**/*.scss', gulp.parallel('scss'));
    gulp.watch('app/*.html', gulp.parallel('html'));
    gulp.watch('app/js/*.js', gulp.parallel('script'));
    gulp.watch('app/*.pug', gulp.parallel('pug'));
    gulp.watch('app/dist/images', gulp.parallel('imagemin'));

});


gulp.task('default', gulp.parallel('scss', 'js', 'browser-sync', 'watch'));

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question