S
S
Sergey Burduzha2021-12-03 10:46:38
FTP
Sergey Burduzha, 2021-12-03 10:46:38

How to fix gulp in conjunction with ftp?

Good afternoon.
I work with sites on wordrpess.
There is a gulp file where I configured and work with webpack.

'use strict';
const gulp = require('gulp');
const webpack = require('webpack-stream');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const sourcemaps = require('gulp-sourcemaps');
const plumber = require('gulp-plumber');
const wait = require('gulp-wait'),
    notify = require('gulp-notify');
const browserSync = require('browser-sync');
const log = require('fancy-log');
let isDev = true;
let webpackConfig = {
    output: {
        filename: 'webpack.js',
    },
    watch: false,
    module: {
        rules: [
            {
                test: /\.m?js$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: [
                            [
                                '@babel/preset-env',
                                {
                                    debug: true,
                                    corejs: 3,
                                    useBuiltIns: 'usage',
                                },
                            ],
                        ],
                    },
                },
            },
        ],
    },
    mode: isDev ? 'development' : 'production',
    devtool: isDev ? 'eval-source-map' : 'none',
};
gulp.task('webpack', function () {
    return gulp
        .src('assets/js/src/main.js')
        .pipe(webpack(webpackConfig))
        .pipe(gulp.dest('assets/js/dist/'))
        .pipe(browserSync.stream());
});
gulp.task('scss', function () {
    return gulp
        .src('assets/scss/my.scss')
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(wait(500))
        .pipe(
            sass().on(
                'error',
                notify.onError(function (error) {
                    return (
                        'An error occurred while compiling sass.\nLook in the console for details.\n' +
                        error
                    );
                })
            )
        )
        .pipe(
            autoprefixer({
                cascade: false,
            })
        )
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('assets/css/'))
        .pipe(browserSync.stream());
});
gulp.task('watch', function () {
    browserSync.init({
        proxy: {
            target: 'https://new2.bludelego.it',
            ws: true,
        },
        reloadDelay: 2000,
        notify: true,
        open: false,
    });
    gulp.watch('**/*.html').on('change', browserSync.reload);
    gulp.watch('**/*.php').on('change', browserSync.reload);
    gulp.watch('**/*.css').on('change', browserSync.reload);
    gulp.watch('assets/js/dist/webpack.js').on('change', browserSync.reload);
    gulp.watch('assets/js/custom-jquery.js').on('change', browserSync.reload);
    gulp.watch('assets/scss/**/*.scss', gulp.series('scss'));
    gulp.watch('assets/js/src/**/*.js', gulp.series('webpack'));
});
gulp.task('default', gulp.series('webpack', 'scss', gulp.parallel('watch')));


After saving the file, it is sent to the server via ftp, after which the page is reloaded.
In fact, the page reloads after a delay, for example 2 sec.
And the problem arises that on the server the code is not written to the end in scss or js files that work through webpack.

For example.
.benefits__title {
    font-weight: no;
}


Or if I send a js file, then the error "unexpected token" in webpack.

To fix it, you have to change something in the css or js file, it's terribly inconvenient.

Maybe someone faced such a problem?

And yet, sites on the server in conjunction with cloudflare.
Could this be the problem?

Thanks in advance.

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