Q
Q
qwerty4567892019-05-02 16:32:54
Browsers
qwerty456789, 2019-05-02 16:32:54

BrowserSync Bitrix not working?

Hello. Help tune gulp for Birtix. I connected BrowserSync, but it only opens the site in the browser and that's it. Nothing happens.

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;

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