isflavior / uglify-php

UglifyPHP is a JavaScript minifier and obfuscator for PHP files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add info: example with pipe

PoeHaH opened this issue · comments

Do you have some info on how to use this with gulp.src().pipe()?

Hello @PoeHaH.

Try this:

const gulp = require("gulp");
const UglifyPHP = require("uglify-php");
const through = require("through2");

gulp.task("minify", function () {
      return gulp.src("test.php")
      .pipe(through.obj(function (chunk, enc, cb) {
            UglifyPHP.minify(chunk.path).then(function (source) {
                  chunk.contents = new Buffer(source);
                  cb(null, chunk);
            });
      }))
      .pipe(gulp.dest("output_path"));
});

Thanks, that works beautifully!