@Denchik102030

Gulp не синхронизирует папку с картинками?

Gulp не синхронизирует папку с картинками автоматически. Для того, чтобы в папке dist/assets/images/ они появились, надо либо вручную добавлять, либо заново в консоле писать gulp

"use strict"

const {src, dest} = require("gulp")
const gulp = require("gulp")

const autoprefixier = require("gulp-autoprefixer");
const del = require("del");
const cssbeautify = require("gulp-cssbeautify");
const cssnano = require("gulp-cssnano");
const imagemin = require("gulp-imagemin");
const plumber = require("gulp-plumber");
const rename = require("gulp-rename");
const rigger = require("gulp-rigger");
const panini = require("panini");
const removeComments = require("gulp-strip-css-comments");
const sass = require("gulp-sass")(require("sass"));
const uglify = require("gulp-uglify")
const notify = require("gulp-notify")
const browserSync = require("browser-sync").create()

// Paths

const srcPath = "src/"
const distPath = "dist/"

const path = {
    build: {
        html: distPath,
        css: distPath + "assets/css/",
        js: distPath + "assets/js/",
        images: distPath + "assets/images/",
        fonts: distPath + "assets/fonts/"
    },
    src: {
        html: srcPath + "*.html",
        css: srcPath + "assets/scss/*.scss",
        js: srcPath + "assets/js/*.js",
        images: srcPath + `assets/images/**/*.{jpg,jpeg,png,svg,gif,webp,ico,xml,json,webmanifest}`,
        fonts: srcPath + "assets/fonts/**/*.{eot, woff, woff2, ttf, svg}"
    },
    watch: {
        html: srcPath + "**/*.html",
        css: srcPath + "assets/scss/**/*.scss",
        js: srcPath + "assets/js/**/*.js",
        images: srcPath + "assets/images/**/*.{jpeg, png, svg, jpg, gif, ico, webp, xml, json, webmanifest}",
        fonts: srcPath + "assets/fonts/**/*.{eot, woff, woff2, ttf, svg}"
    },
    clean: "./" + distPath
}

function serve() {
    browserSync.init({
        server: {
            baseDir: "./" + distPath
        }
    })
}

function html () {
    return src(path.src.html, { base: srcPath })
        .pipe(plumber())
        .pipe(dest(path.build.html))
        .pipe(browserSync.reload({stream: true}));
}

function css () {
    return src(path.src.css, { base: srcPath + "assets/scss/" })
    .pipe(plumber({
        errorHandler : function(err) {
            notify.onError({
                title: "SCSS Error",
                message: "Error: <%= error.message %>"
            })(err);
            this.emit('end');
        }
    }))
        .pipe(sass())
        .pipe(autoprefixier())
        .pipe(cssbeautify())
        .pipe(dest(path.build.css))
        .pipe(cssnano({
            zindex: false,
            discardComments: {
                removeAll: true
            }
        }))
        .pipe(removeComments())
        .pipe(rename({
            suffix: ".min",
            extname: ".css"
        }))
        .pipe(dest(path.build.css))
        .pipe(browserSync.reload({stream: true}));
}

function js() {
    return src(path.src.js, { base: srcPath + "assets/js/" })
    .pipe(plumber({
        errorHandler : function(err) {
            notify.onError({
                title: "JS Error",
                message: "Error: <%= error.message %>"
            })(err);
            this.emit('end');
        }
    }))
        .pipe(rigger())
        .pipe(dest(path.build.js))
        .pipe(uglify())
        .pipe(rename({
            suffix: ".min",
            extname: ".js"
        }))
        .pipe(dest(path.build.js))
        .pipe(browserSync.reload({stream: true}));
}

function images() {
    return src(path.src.images, { base: srcPath + "assets/images/" })
        .pipe(imagemin([
            imagemin.gifsicle({interlaced: true}),
            imagemin.mozjpeg({quality: 80, progressive: true}),
            imagemin.optipng({optimizationLevel: 5}),
            imagemin.svgo({
                plugins: [
                    {removeViewBox: true},
                    {cleanupIDs: false}
                ]
            })
        ]))
        .pipe(dest(path.build.images))
        .pipe(browserSync.reload({stream: true}));
}

function clean() {
    return del(path.clean)
}

function fonts() {
    return src(path.src.fonts, { base: srcPath + "assets/fonts/" })
    .pipe(browserSync.reload({stream: true}));
}

function watchFiles() {
    gulp.watch([path.watch.html], html)
    gulp.watch([path.watch.css], css)
    gulp.watch([path.watch.js], js)
    gulp.watch([path.watch.images], images)
    gulp.watch([path.watch.fonts], fonts)
}

const build = gulp.series(clean, gulp.parallel(html, css, js, images, fonts))

const watch = gulp.parallel(build, watchFiles, serve)

exports.fonts = fonts
exports.images = images
exports.css = css
exports.html = html
exports.js = js
exports.clean = clean
exports.build = build
exports.watch = watch
exports.default = watch
  • Вопрос задан
  • 65 просмотров
Пригласить эксперта
Ответы на вопрос 1
@Froggyweb
потому что задача указана только в сценарии build
каким образом ты привязал тег сss grid?
Ответ написан
Ваш ответ на вопрос

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

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