A
A
Andrew Chil2017-06-14 17:29:32
css
Andrew Chil, 2017-06-14 17:29:32

gulp browserSync(openserver) error?

Good afternoon! Please tell me where is the error in gulp. I'm trying to set up livereload gulp on an open server (magento).
When running gulp, it redirects to localhost:3000/, shows that browserSync is connected, but does not work.

var gulp = require("gulp"),
    util = require("gulp-util"),
    sass = require("gulp-sass"),
    plumber = require('gulp-plumber'),
    image = require('gulp-image'),
    cleanCSS = require('gulp-clean-css'),
    rename = require('gulp-rename'),
    log = util.log,
    concat = require('gulp-concat'),
    babel = require("gulp-babel"),
    uglify = require('gulp-uglify'),
    debug = require('gulp-debug'),
    autoprefixer = require('gulp-autoprefixer'),
    browserSync = require('browser-sync').create(),
    runSequence = require('run-sequence'),
    sourcemaps = require('gulp-sourcemaps'),
    plugins = require('gulp-load-plugins')({});

gulp.task("sass", function () {
    log("Generate CSS files " + (new Date()).toString());
    gulp.src("build/styles/main.scss")
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(sass({style: 'expanded'}))
        .pipe(autoprefixer({browsers: ['last 5 version'], cascade: false}))
        .pipe(sourcemaps.write("./"))
        .pipe(gulp.dest("dest/css"))
        .pipe(cleanCSS())
        .pipe(rename({
            basename: 'styles',
            suffix: '.min'
        }))
        .pipe(gulp.dest('dest/css'))
        .pipe(browserSync.stream());

});


gulp.task('browser-sync', ['sass'], function () {
    browserSync.init({
        proxy: "http://mydomen/"
    });
});

gulp.task('scripts', function () {
    return gulp.src('build/scripts/*.js')
        .pipe(plumber())
        .pipe(debug())
        .pipe(concat('all.js'))
        .pipe(babel({
            presets: ['es2015']
        }))
        .pipe(rename({
            basename: 'main'
        }))
        .pipe(gulp.dest('dest/js'))
        .pipe(uglify())
        .pipe(rename({
            basename: 'main',
            suffix: '.min'
        }))
        .pipe(gulp.dest('dest/js'))
});

gulp.task('image', function () {
    gulp.src('./build/img/*')
        .pipe(image({
            pngquant: true,
            optipng: true,
            zopflipng: true,
            jpegRecompress: false,
            jpegoptim: true,
            mozjpeg: true,
            gifsicle: true,
            svgo: true,
            concurrent: 10
        }))
        .pipe(gulp.dest('./dest/img'));
});

gulp.task('default', function (callback) {
    runSequence(['sass', 'scripts', 'browser-sync', 'watch'], callback)
});
// plugins.livereload.listen();
gulp.task("watch", function () {
    // livereload.listen();
    log("Watching scss files for modifications");
    gulp.watch('build/styles/**/*.scss', ['sass']);
    gulp.watch('build/scripts/*.*', ['scripts']);
    gulp.watch('/**/*.php').on('change', browserSync.reload);
    gulp.watch('build/styles/**/*.scss').on('change', browserSync.reload);
    gulp.watch('dest/css/*.css').on('change', browserSync.reload);
});

I will be grateful for your help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan, 2017-06-15
@rOOse

And so?

gulp.task("watch", function () {
    // livereload.listen();
    log("Watching scss files for modifications");
    gulp.watch('build/styles/**/*.scss', ['sass']);
    gulp.watch('build/scripts/*.*', ['scripts']);
    gulp.watch('/**/*.php').on('change', browserSync.reload);
    gulp.watch('build/styles/**/*.scss').on('change', browserSync.reload);
    gulp.watch('dest/css/*.css').on('change', browserSync.reload);
    browserSync.init({
        proxy: "http://mydomen/"
    });
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question