@Mile4311112

Почему при **gulp build** не все файлы редактирует?

'use strict';

const
    gulp = require('gulp'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    autoprefixer = require('gulp-autoprefixer'),
    gutil = require('gulp-util'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    rename = require("gulp-rename"),
    plumber = require('gulp-plumber'),
    cssmin = require('gulp-minify-css'),
    babel = require('gulp-babel'),
    browserSync = require('browser-sync'),
    reload = browserSync.reload,
    notify = require("gulp-notify"),
    replace = require("gulp-replace"),
    fs = require("fs"),
    async = require('async'),
    rev = require('gulp-rev');

gulp.task('build', [
    'sass',
    'js'
]);

gulp.task('un_build_all', [
    'unsass',
    'unjs'
]);

gulp.task('browserSync', function() {
    browserSync({
        server: {
            baseDir: "./src"
        },
        port: 8080,
        open: true,
        notify: false
    });
});

// gulp.task('vendor-js', function () {
//     return gulp.src('js/vendor/*.js')
//         .pipe(concat('newvendor.js'))
//         .pipe(uglify())
//         .pipe(gulp.dest('js'))
//         .pipe(rename('newvendor.min.js'))
//         .pipe(gulp.dest('js'));
// });


gulp.task('js', function() {
    async.series([
        function(next) {
            gulp.src('js/custom/index.js')
                .pipe(babel({ presets: ['env'] }))
                .pipe(concat('main.js'))
                .pipe(gulp.dest('js'))
                .pipe(uglify())
                .pipe(rename('main.min.js'))
                .pipe(rev())
                .pipe(gulp.dest('js'))
                .pipe(rev.manifest())
                .pipe(gulp.dest('js'))
                .on('end', next)
                .on('error', gutil.log)

        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['*/*.html'], { base: './' })
                .pipe(replace(/main\.min\.js/g, json['main.min.js']))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['**/*.php'], { base: './' })
                .pipe(replace(/main\.min\.js/g, json['main.min.js']))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['*/*.php'], { base: './' })
                .pipe(replace(/main\.min\.js/g, json['main.min.js']))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['**/*.html'], { base: './' })
                .pipe(replace(/main\.min\.js/g, json['main.min.js']))
                .pipe(gulp.dest('.'));
        }
    ]);
});
gulp.task('unjs', function() {
    async.series([
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['**/*.html'], { base: './' })
                .pipe(replace(new RegExp(json['main.min.js'].replace(/\./g, "\\."), 'g'), 'main.min.js'))
                .pipe(gulp.dest('.'))
                .on('end', next);

        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['*/*.html'], { base: './' })
                .pipe(replace(new RegExp(json['main.min.js'].replace(/\./g, "\\."), 'g'), 'main.min.js'))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['**/*.php'], { base: './' })
                .pipe(replace(new RegExp(json['main.min.js'].replace(/\./g, "\\."), 'g'), 'main.min.js'))
                .pipe(gulp.dest('.'))
                .on('end', next);

        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            gulp.src(['*/*.php'], { base: './' })
                .pipe(replace(new RegExp(json['main.min.js'].replace(/\./g, "\\."), 'g'), 'main.min.js'))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('js/rev-manifest.json'));
            fs.unlinkSync('js/' + json['main.min.js']);
            fs.unlinkSync('js/rev-manifest.json');
        }
    ]);
});

gulp.task('sass', function() {
    async.series([
        function(next) {
            gulp.src('scss/*.scss')
                .pipe(plumber())
                .pipe(sourcemaps.init())
                .pipe(sass())
                .pipe(
                    sass().on('error', function(e) {
                        gutil.log(e);
                    })
                )
                .pipe(
                    autoprefixer({
                        browsers: ['last 3 versions'],
                        cascade: false
                    })
                )
                .pipe(gulp.dest('css'))
                .pipe(cssmin())
                .pipe(sourcemaps.write())
                .pipe(rename('style.min.css'))
                .pipe(rev())
                .pipe(gulp.dest('css'))
                .pipe(rev.manifest())
                .pipe(gulp.dest('css'))
                .on('end', next)
                .pipe(reload({ stream: true }));
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('css/rev-manifest.json'));
            gulp.src('**/*.html', { base: './' })
                .pipe(replace(/style\.min\.css/g, json['style.min.css']))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('css/rev-manifest.json'));
            gulp.src('**/*.php', { base: './' })
                .pipe(replace(/style\.min\.css/g, json['style.min.css']))
                .pipe(gulp.dest('.'))
                .on('end', next);
        }
    ]);


});
gulp.task('unsass', function() {
    async.series([
        function(next) {
            var json = JSON.parse(fs.readFileSync('css/rev-manifest.json'));
            gulp.src('**/*.html', { base: "./" })
                .pipe(replace(new RegExp(json['style.min.css'].replace(/\./g, "\\."), 'g'), 'style.min.css'))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('css/rev-manifest.json'));
            gulp.src('**/*.php', { base: './' })
                .pipe(replace(new RegExp(json['style.min.css'].replace(/\./g, "\\."), 'g'), 'style.min.css'))
                .pipe(gulp.dest('.'))
                .on('end', next);
        },
        function(next) {
            var json = JSON.parse(fs.readFileSync('css/rev-manifest.json'));
            fs.unlinkSync('css/' + json['style.min.css']);
            fs.unlinkSync('css/rev-manifest.json');
        }
    ]);
});

gulp.task('watch', function() {
    gulp.watch('js/custom/*.js', ['js']);
});

gulp.task('watch-scss', function() {
    gulp.watch('scss/*.scss', ['scss']);
});

gulp.task('default', ['build', 'watch', 'browserSync']);


gulp build -> style.min.css gulp un_build_all -> style-3d96362fb4.min.css

Почему при gulp build не все файлы редактирует с style-3d96362fb4.min.css в style.min.css
  • Вопрос задан
  • 40 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы