O
O
Orsen62022-03-16 17:57:47
PHP
Orsen6, 2022-03-16 17:57:47

Is it possible to make GULP run index.php?

I need to change Gulp's tracking to follow .php instead of HTML files.

const scss = require('gulp-sass')(require('sass'));
const { src, dest, watch, parallel } = require('gulp');
var concat = require('gulp-concat');
const autoprefixer = require('gulp-autoprefixer');
const uglify = require('gulp-uglify');
const browserSync = require('browser-sync').create();


function browsersync(){
  browserSync.init({
    server: {
        baseDir: "app"
    }
});
}


function styles() {
  return src('app/scss/style.scss')
    .pipe(scss({outputStyle: 'expanded'}))
    .pipe(concat('style.css'))
    .pipe(autoprefixer({
      overrideBrowserslist: ['last 10 versions'],
      grid: true
    }))
    .pipe(dest('app/css'))
    .pipe(browserSync.stream())
}


function scripts() {
  return src([
    'app/js/main.js'
  ])
  .pipe(concat('main.min.js'))
  .pipe(uglify())
  .pipe(dest('app/js'))
  .pipe(browserSync.stream())
}

function watching() {
  watch(['app/scss/**/*.scss'], styles);
  watch(['app/js/**/*.js', '!app/js/main.min.js'], scripts);
  watch(['app/**/*.html']).on('change', browserSync.reload);
}

exports.styles = styles;
exports.scripts = scripts;
exports.browsersync = browsersync;
exports.watching = watching;

exports.default = parallel(styles, scripts, browsersync, watching);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Shamanov, 2022-03-16
@SilenceOfWinter

gulp tracks changes by date or file size, alas, a php script can contain include and return different results, while the date of modification and file size will remain unchanged. and what's the point in all of that? you can add gulp call in php generated html or call console command in php code

F
Froggyweb, 2022-03-16
@Froggyweb

gulp reload php -> https://stackoverflow.com/questions/23448256/gulp-...
if you don't like it, you can add browsersync reload php
but that's all if the files are located locally, if on the server, then nothing....

S
Sergey delphinpro, 2022-03-16
@delphinpro

Well, add it, business something ...

function watching() {
  watch(['app/scss/**/*.scss'], styles);
  watch(['app/js/**/*.js', '!app/js/main.min.js'], scripts);
  // watch(['app/**/*.html']).on('change', browserSync.reload);
  watch(['app/**/*.php']).on('change', browserSync.reload);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question