D
D
Daniel2021-06-18 08:29:14
PHP
Daniel, 2021-06-18 08:29:14

Why doesn't gulp parse PHP?

Hello. I have a problem, gulp does not parse two PHP files (responsible for sending email) when building a project. It just minifies them into a mess and these files do not perform their functions at the output. In the gulp script, minification is registered only for css and js .., I don’t understand what’s the matter (((

GULP script
/* It's principal settings in smart grid project */
let settings = {
    outputStyle: 'less', /* less || scss || sass || styl */
    columns: 12, /* number of grid columns */
    offset: '30px', /* gutter width px || % || rem */
    mobileFirst: false, /* mobileFirst ? 'min-width' : 'max-width' */
    container: {
        maxWidth: '1230px', /* max-width оn very large screen */
        fields: '15px' /* side fields */
    },
    breakPoints: {
        lg: {
            width: '1100px', /* -> @media (max-width: 1100px) */
        },
        md: {
            width: '960px'
        },
        sm: {
            width: '780px',
            fields: '15px' /* set fields only if you want to change container.fields */
        },
        xs: {
            width: '560px'
        }
        /* 
        We can create any quantity of break points.

        some_name: {
            width: 'Npx',
            fields: 'N(px|%|rem)',
            offset: 'N(px|%|rem)'
        }
        */
    }
};





//Папки исходников и проекта
let project_folder = '../domains/ameks/'; //require("path").basename(__dirname)
let source_folder = '#src';

let fs = require('fs');

let path = {
    build: {
        php: project_folder + "/",
        css: project_folder + "/css/",
        js: project_folder + "/js/",
        img: project_folder + "/css/img/",
        fonts: project_folder + "/css/fonts/",
    },
    src: {
        php: source_folder+"/**/*.php",
        css: source_folder+"/css/style.less", //**/*.{less,css}
        js: source_folder+"/js/script.js",
        img: source_folder+"/img/**/*.{png,jpg,svg,gif,ico,webp}",
        fonts: source_folder+"/fonts/**/*.ttf",
    },
    watch: {
        php: source_folder+"/**/*.php",
        css: source_folder+"/css/**/*.less",
        js: source_folder+"/js/**/*.js",
        img: source_folder+"/img/**/*.{png,jpg,svg,gif,ico,webp}",
    },
    clean: project_folder
}

//Переменные плагинов
let {src, dest} = require('gulp'), 
    gulp = require('gulp'),
    browsersync = require('browser-sync').create(), //"Живая вёрстка"
    fileinclude = require('gulp-file-include'), //Соединение нескольких файлов в один
    del = require('del'), //Очистка папки проекта перед сборкой
    connectPHP = require('gulp-connect-php'), //Открытие сервера на PHP
    less = require('gulp-less'), //Работа с less
    autoprefixer = require('gulp-autoprefixer'), //Автопрефиксы
    group_media = require('gulp-group-css-media-queries'), //Группировка медиа-запросов
    clean_css = require('gulp-clean-css'), //Минификация CSS
    rename = require('gulp-rename'), //Переименование файлов
    babelJS = require('gulp-babel'), //Конвертация нового кода JS в старый
    uglify = require('gulp-uglify-es').default, //Минификация JS
    imagemin = require('gulp-imagemin'), //Сжатие картинок
    webp = require('gulp-webp'), //Конвертация картинок в современный формат
    webphtml = require('gulp-webp-html'), //Вставка совр. картинок в разметку
    webpcss = require('gulp-webpcss'), //Вставка совр. картинок в стили
    ttf2woff = require('gulp-ttf2woff'), //Конвертация шрифтов
    ttf2woff2 = require('gulp-ttf2woff2'), //Конвертация шрифтов
    fonter = require('gulp-fonter'), //Конвертация шрифтов
    smartgrid = require('smart-grid');

    smartgrid('#src/css/libs', settings);


function browserSync() {
    browsersync.init({
        proxy: 'ameks',
        notify: false,
        port: 80
    })
}

//Запуск сервера
  function connect() {
    connectPHP.server({ base: './' + project_folder + './', keepalive:true, hostname: 'ameks', port:80, open: false});
  }

//Перенос файлов PHP
  function php() {
    return src(path.src.php)
        .pipe(webphtml())
        .pipe(dest(path.build.php))
        .pipe(browsersync.stream())
  }

//Перенос Изображений (картинок)
  function images() {
    return src(path.src.img)
        .pipe(
          webp({
            quality: 70
          })
        )
        .pipe(dest(path.build.img))
        .pipe(src(path.src.img))
        .pipe(
          imagemin({
            progressive: true,
            svgoPlugins: [{ removeViewBox: false }],
            interplaced: true,
            optimizationLevel: 7, // от 0 до 7
          })
        )
        .pipe(dest(path.build.img))
        .pipe(browsersync.stream())
  }

//Перенос файлов CSS + компиляция из Less
  function css() {
    return src(path.src.css)
        .pipe(
            less({
                path: path.src.css
            })
        )
        .pipe(group_media()) 
        .pipe(
          autoprefixer({ 
            overrideBrowserslist: ['last 20 versions'], 
            cascade: true
          })
        )
        .pipe(webpcss({
            webpClass: '.webp',
            noWebpClass: '.no-webp',
        }))
        .pipe(dest(path.build.css)) //Выгрузка исходного CSS
        .pipe(clean_css())
        .pipe(
          rename({
            extname: ".min.css"
          })
        )
        .pipe(dest(path.build.css)) //Выгрузка сжатого CSS
        .pipe(browsersync.stream())
  }

//Перенос файлов JS
  function js() {
    return src(path.src.js)
        .pipe(fileinclude())
        .pipe(babelJS())
        .pipe(dest(path.build.js))
        .pipe(uglify()) 
        .pipe(
          rename({
            extname: ".min.js"
          })
        )
        .pipe(dest(path.build.js))
        .pipe(browsersync.stream())
  }

//Перенос шрифтов
  function fonts() {
    src(path.src.fonts)
      .pipe(ttf2woff())
      .pipe(dest(path.build.fonts))
    return src(path.src.fonts)
      .pipe(ttf2woff2())
      .pipe(dest(path.build.fonts))
  }
  gulp.task('otf2ttf', function() {
    return src([source_folder + '/fonts/*.otf'])
      .pipe(fonter({
        formats: ['ttf']
      }))
      .pipe(dest(source_folder + '/fonts/'));
  })


  function fontsStyle() {
  
    let file_content = fs.readFileSync(source_folder + '/css/fonts.less');
    if (file_content == '') {
      fs.writeFile(source_folder + '/css/fonts.less', '', cb);
      return fs.readdir(path.build.fonts, function (err, items) {
        if (items) {
          let c_fontname;
          for (var i = 0; i < items.length; i++) {
            let fontname = items[i].split('.');
            fontname = fontname[0];
              if (c_fontname != fontname) {
                fs.appendFile(source_folder + '/css/fonts.less', '.font("' + fontname + '", "' + fontname + '", 400, normal);\r\n', cb);
              }
              c_fontname = fontname;
          }
        }
      })
    }
  }
  
  function cb() {

  }

//Живое обновление файлов
  function wathFiles() {
      gulp.watch([path.watch.php], php);
      gulp.watch([path.watch.css], css);
      gulp.watch([path.watch.js], js);
      gulp.watch([path.watch.img], images);
  }

//Очистка папки проекта перед сборкой
  function clean() {
    return del([path.clean], {force: true})
  }

let build = gulp.series(clean, gulp.parallel(js, css, php, images, fonts), fontsStyle, connect);
let watch = gulp.parallel(build, wathFiles, browserSync);


//Задачи для Gulp
exports.fontsStyle = fontsStyle;
exports.fonts = fonts;
exports.images = images;
exports.js = js;
exports.css = css;
exports.php = php;
exports.build = build;
exports.watch = watch;
exports.default = watch;

Result after build
60cc2ef3e5238375599299.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-06-18
@daniel333

//Перенос файлов PHP
  function php() {
    return src(path.src.php)
   //     .pipe(webphtml()) Вот эту хрень выбросите
        .pipe(dest(path.build.php))
        .pipe(browsersync.stream())
  }

And immediately insert the pictures yourself in modern formats.
This plugin is completely useless. Even harmful, in a sense.

D
Daniel, 2021-06-18
@daniel333

I also found a solution to this problem for my part) The message in the photo was tired of popping up and decided to get rid of it. Added path to php.exe of my openServer via Windows 10 environment variables (no rules in VS Code). I did this on a working computer, after which the problem appeared. I didn’t do anything on my home laptop (Windows 7), I ignore the message. But GULP with all plugins works as expected. Maybe someone will be useful

A photo
60ccaf96cb645711738851.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question