@qwerty456789

Не работает browserSync Bitrix?

Всем привет. Помогите донастроить gulp для Birtix. Подключил BrowserSync, но он только открывает в браузере сайт и все. Ничего не происходит.
import gulp from 'gulp';
import rename from 'gulp-rename';
import sass from 'gulp-sass';
import babel from 'gulp-babel';
import uglify from 'gulp-uglify';
import cleanCSS from 'gulp-clean-css';
import sourcemaps from 'gulp-sourcemaps';
import imagemin from 'gulp-imagemin';
import changed from 'gulp-changed';
import path from 'path';
import autoprefixer from 'gulp-autoprefixer';
var browserSync = require("browser-sync").create();

const base = 'www';
const server = 'btdn.my';
const mytheme = 'bntd';

const paths = {
    styles: {
        src: [
            './local/templates/*/css/**/!(*.min).?(s)css',
            './local/templates/.*/css/**/!(*.min).?(s)css',

            './local/templates/*/components/**/!(*.min).?(s)css',
            './local/templates/*/components/**/.*/!(*.min).?(s)css',
            './local/templates/.*/components/**/!(*.min).?(s)css',
            './local/templates/.*/components/**/.*/!(*.min).?(s)css',
        ],
        dest: './' + base + '/'
    },
    scripts: {
        src: [
            './local/templates/*/js/**/!(*.min).js',
            './local/templates/.*/js/**/!(*.min).js',

            './local/templates/*/components/**/!(*.min).js',
            './local/templates/*/components/**/.*/!(*.min).js',
            './local/templates/.*/components/**/!(*.min).js',
            './local/templates/.*/components/**/.*/!(*.min).js',
        ],
        dest: './' + base + '/'
    },
    images: {
        src: [
            './local/templates/*/images/**/!(*.min).+(png|gif|jpg|jpeg|svg)',
            './local/templates/.*/images/**/!(*.min).+(png|gif|jpg|jpeg|svg)',

            './local/templates/*/components/**/images/**/!(*.min).+(png|gif|jpg|jpeg|svg)',
            './local/templates/*/components/**/.*/images/**/!(*.min).+(png|gif|jpg|jpeg|svg)',
            './local/templates/.*/components/**/images/**/!(*.min).+(png|gif|jpg|jpeg|svg)',
            './local/templates/.*/components/**/.*/images/**/!(*.min).+(png|gif|jpg|jpeg|svg)',
        ],
        dest: './' + base + '/'
    },


};

export function styles() {
    let oldExtension;

    return gulp.src(paths.styles.src, {dot: true, base: base})
        .pipe(rename(function (path) {
            oldExtension = path.extname;
            path.basename += ".min";
            path.extname = ".css";
        }))
        .pipe(sourcemaps.init())
        .pipe(changed(paths.styles.dest))
        .pipe(sass().on('error', sass.logError))
        .pipe(autoprefixer())
        .pipe(cleanCSS())
        .pipe(sourcemaps.mapSources(function(sourcePath, file) {
            sourcePath = path.basename(sourcePath, '.min.css') + oldExtension;
            return sourcePath;
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(paths.styles.dest))
        .pipe(browserSync.reload({stream:true}));
}

export function scripts() {
    return gulp.src(paths.scripts.src, {dot: true, base: base})
        .pipe(sourcemaps.init())
        .pipe(rename({
            suffix: ".min"
        }))
        .pipe(changed(paths.scripts.dest))
        .pipe(babel())
        .pipe(uglify())
        .pipe(sourcemaps.mapSources(function(sourcePath, file) {
            sourcePath = path.basename(sourcePath, '.min.js') + '.js';
            return sourcePath;
        }))
        .pipe(sourcemaps.write('./'))
        .pipe(gulp.dest(paths.scripts.dest))
        .pipe(browserSync.reload({stream:true}));
}

export function images() {
    return gulp.src(paths.images.src, {dot: true, base: base})
        .pipe(rename({
            suffix: ".min"
        }))
        .pipe(changed(paths.images.dest))
        .pipe(imagemin())
        .pipe(gulp.dest(paths.images.dest))
        .pipe(browserSync.reload({stream:true}));
}

export function sync() {
    browserSync.init({
        watch: true,
        proxy: server,
        notify: false,
        files: ["./local/templates/.*/css/**/*scss"]
    })
}

export function watch() {
    gulp.watch(paths.scripts.src, scripts);
    gulp.watch(paths.styles.src, styles);
    gulp.watch(paths.images.src, images);
}

const build = gulp.series(gulp.parallel(sync, styles, scripts, images), watch);
export default build;
  • Вопрос задан
  • 104 просмотра
Пригласить эксперта
Ваш ответ на вопрос

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

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