Olá!
Alguém pode me ajudar a implementar o código que minifica os arquivos PHP?
Encontrei este código em https://tonicdev.com/npm/gulp-php-minify:
const gulp = require('gulp'); const phpMinify = require('gulp-php-minify');
gulp.task('minify:php', () => gulp.src('path/to/lib/*/.php', {read: false}) .pipe(phpMinify()) .pipe(gulp.dest('path/to/out')) );
No meu gulpfile.js, complementando o do curso, deixei assim:
var gulp = require('gulp') ,imagemin = require('gulp-imagemin') ,clean = require('gulp-clean') ,concat = require('gulp-concat') ,htmlReplace = require('gulp-html-replace') ,uglify = require('gulp-uglify') ,usemin = require('gulp-usemin') ,cssmin = require('gulp-cssmin') ,browserSync = require('browser-sync').create() ,jshint = require('gulp-jshint') ,jshintStylish = require('jshint-stylish') ,csslint = require('gulp-csslint') ,autoprefixer = require('gulp-autoprefixer') ,less = require('gulp-less');
const phpMinify = require('gulp-php-minify');
E implementei a tarefa assim:
gulp.task('minify-php', () => gulp.src('dist/*/.php', {read: false}) .pipe(phpMinify()) .pipe(gulp.dest('dist')) );
Dá um erro, que é o seguinte: [10:36:11] Using gulpfile ~\Desktop\teste\gulpfile.js [10:36:11] Starting 'minify-php'... events.js:160 throw er; // Unhandled 'error' event ^
Error: [gulp-php-minify] Error: Command failed: "php" -w "C:\Users\Alexandre\Des ktop\teste\dist\anuncie-aqui.php" '"php"' n?o ? reconhecido como um comando interno ou externo, um programa oper?vel ou um arquivo em lotes.
at child.exec (C:\Users\Alexandre\Desktop\teste\node_modules\gulp-php-minify \lib\php_minifier.js:44:24) at ChildProcess.exithandler (child_process.js:213:5) at emitTwo (events.js:106:13) at ChildProcess.emit (events.js:191:7) at maybeClose (internal/child_process.js:852:16) at Socket. (internal/child_process.js:323:11) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at Pipe._handle.close [as _onclose] (net.js:492:12)
npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\
node_modules\npm\bin\npm-cli.js" "run" "gulp" "minify-php"
npm ERR! node v6.4.0
npm ERR! npm v2.15.9
npm ERR! code ELIFECYCLE
npm ERR! teste@1.0.0 gulp: gulp "minify-php"
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the teste@1.0.0 gulp script 'gulp "minify-php"'.
npm ERR! This is most likely a problem with the teste package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! gulp "minify-php"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs teste
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls teste
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request: npm ERR! C:\Users\Alexandre\Desktop\teste\npm-debug.log