Problem with Gulp Build

1

In my project I am using Gulp. I have two problems:

  • Do not copy the images to the dist folder. I am using imagemin . I have already checked the directory multiple times, but I do not see the error. My folders are organized as follows:

    |- app/ |- css/ |- fonts/ |- images/ |- index.html |- js/ |- jQuery Nice Select/ |- jQuery Validation/ |- scss/ |- dist/ |- gulpfile.js |- node_modules/ |- package.json

  • I am using the Nice Select plugin and jQuery Validate and it seems not to include them in the build, since when viewing the page in production, the select it appears as the default of the browser and the validations do not work.

  • HTML

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
        <!--build:js js/main.min.js -->
        <script src="js/simulador.js"></script>         
        <script src="js/main.js"></script>
        <script src="https://www.google.com/recaptcha/api.js"></script>
    
        <script src="js/lib/jquery-validation-1.16.0/dist/jquery.validate.js"></script>
        <script src="js/lib/jquery-nice-select/jquery.nice-select.js"></script>
        <!-- endbuild -->
    

    gulpfile.js

    var gulp = require('gulp');
    var sass = require('gulp-sass');
    var browserSync = require('browser-sync').create();
    var useref = require('gulp-useref');
    var uglify = require('gulp-uglify');
    var gulpIf = require('gulp-if');
    var imagemin = require('gulp-imagemin');
    var cache = require('gulp-cache');
    var cssnano = require('gulp-cssnano');
    var del = require('del');
    var runSequence = require('run-sequence');
    var debug = require('gulp-debug');
    
    
    gulp.task('sass', function(){
        return gulp.src('app/scss/**/*.scss')
          .pipe(sass()) // Using gulp-sass
          .pipe(gulp.dest('app/css'))
          .pipe(browserSync.reload({
            stream: true
        }))
    });
    
    gulp.task('browserSync', function() {
        browserSync.init({
            server: {
            baseDir: 'app'
            },
        })
    });
    
    gulp.task('useref', function(){
        return gulp.src('app/*.html')
            .pipe(useref())
            .pipe(gulpIf('*.js', uglify()))
            .pipe(gulpIf('*.css', cssnano()))
            .pipe(gulp.dest('dist'))
    });
    
    gulp.task('images', function(){
        return gulp.src('app/images/**/*.+(png|jpg|gif|svg)')
        .pipe(cache(imagemin({
            interlaced: true
        })))
        .pipe(gulp.dest('dist/images'))
    });
    
    gulp.task('fonts', function() {
        return gulp.src('app/fonts/**/*')
        .pipe(gulp.dest('dist/fonts'))
    });
    
    gulp.task('clean:dist', function() {
        return del.sync('dist');
    });
    
    gulp.task('watch', ['browserSync', 'sass'], function(){
        gulp.watch('app/scss/**/*.scss', ['sass']); 
        gulp.watch('app/*.html', browserSync.reload); 
        gulp.watch('app/js/**/*.js', browserSync.reload); 
    });
    
    gulp.task('build', function (callback) {
        runSequence('clean:dist', 
          ['sass', 'useref', 'images', 'fonts'],
          callback
        )
    });
    
        
    asked by TheWoodStudio 31.10.2017 в 14:45
    source

    1 answer

    0

    I solved it in the following way:

    1) Theme images:

    gulp.task('images', function() {
        return gulp.src('app/images/**/*.+(png|jpg|gif|svg)')
            .pipe(imagemin(cache({
                interlaced: true
            })))
            .pipe(gulp.dest('dist/images'))
    });
    

    The solution lies in putting cache after imagemin . In the reverse way, I did not take it.

    2) Theme plugins: In some strange way, cssnano interfered with the min% of js . I changed to cleanCSS and now everything works perfect.

        
    answered by 09.11.2017 / 17:10
    source