cedx / php-minifier Goto Github PK
View Code? Open in Web Editor NEWMinify PHP source code by removing comments and whitespace.
Home Page: https://github.com/cedx/php-minifier/wiki
License: MIT License
Minify PHP source code by removing comments and whitespace.
Home Page: https://github.com/cedx/php-minifier/wiki
License: MIT License
When i run 'gulp php:build', terminal said: 'Minifying: path/to/files/file.php' but files don't minifying and i didn't see files in my dest folder.
const {phpMinify} = require('@cedx/gulp-php-minify');
gulp.task('php:build', () => gulp.src(path.src.php, {read: false})
.pipe(phpMinify())
.pipe(gulp.dest(path.build.php))
);
Whats problem?
Hello!
I'm getting this error when running the gulp task:
I'm using npm v6.10.3 and node v12.8.0. I'm also using babel.
Can someone give me a light on how to solve this?
This is my code:
import {src, dest, watch, series, parallel} from 'gulp';
import {phpMinify} from "@cedx/gulp-php-minify";
export const php = () => {
return src("includes/**/*.php", {read: false})
.pipe(phpMinify())
.pipe(dest('inc'));
};
I've also tried using this approach, but got the same error:
import gulp from 'gulp';
import {phpMinify} from "@cedx/gulp-php-minify";
gulp.task('compress:php', () => gulp.src('includes/**/*.php', {read: false})
.pipe(phpMinify())
.pipe(gulp.dest('inc'))
);
Hi,
Implement everything as instructed, but do not minimize and the following "Task never defined: default" always appears when using 'gulp'.
In the gulpfile.js file I used:
import {phpMinify, TransformMode} from '@cedx/gulp-php-minify';
import gulp from 'gulp';
/** Compresses a given set of PHP scripts. */
gulp.task('compressPhp', () => gulp.src('src/**/*.php', {read: false})
.pipe(phpMinify({
binary: process.platform == 'win32' ? String.raw`C:\MAMP\bin\php\php7.2.14\php.exe` : '/usr/bin/php',
mode: process.platform == 'win32' ? TransformMode.safe : TransformMode.fast,
silent: process.stdout.isTTY
}))
.pipe(gulp.dest('src_min'))
);
import {phpMinify} from '@cedx/gulp-php-minify';
import gulp from 'gulp';
gulp.task('compress:php', () => gulp.src('src/**/*.php', {read: false})
.pipe(phpMinify({mode: TransformMode.safe}))
.pipe(gulp.dest('src_min'))
);
Please help :)
Jaime
I have tried with with "@cedx/gulp-php-minify": "^7.1.1",
var phpMinify = require('@cedx/gulp-php-minify'),
gulp.task('phpMinify', function() {
gulp.src(source + '**/*.php')
.pipe(phpMinify({
silent: true,
removeComments: true,
collapseWhitespace: true,
}))
.pipe(gulp.dest(dest));
}),
It says
λ gulp phpMinify
[20:34:00] Using gulpfile G:\Workflows_script\gulpfile.js
[20:34:00] Starting 'phpMinify'...
[20:34:00] 'phpMinify' errored after 13 ms
[20:34:00] TypeError: phpMinify is not a function
at Gulp.<anonymous> (G:\Workflows_script\gulpfile.js:23:11)
at module.exports (G:\Workflows_script\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (G:\Workflows_script\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (G:\Workflows_script\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (G:\Workflows_script\node_modules\orchestrator\index.js:134:8)
at C:\Users\Abhay\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
at Function.Module.runMain (module.js:686:11)
at startup (bootstrap_node.js:187:16)
All resource link provided on readme file is dead.
Hi
I'm really struggling.
I have a gulpfile.js
with CommonJS format, and I'm in deep need of using @cedx/gulp-php-minify. What ever I do, I can't manage to make it work, and I can't really change the use of CommonJS in the gulpfile.js
.
I tried all of these:
const esm = require("esm")(module);
const phpMinify = import("@cedx/gulp-php-minify")(module);
const phpMinify = esm("@cedx/gulp-php-minify");
const phpMinify = esm("./node_modules/@cedx/gulp-php-minify");
const phpMinify = require("@cedx/gulp-php-minify");
const phpMinify = require("@aquafadas/gulp-php-minify");
import phpMinify from "@cedx/gulp-php-minify";
What should I do?
Thanks to the esm
package, this plugin currently works as expected. But when Gulp will natively support ES modules, I doubt that this still will be the case in the future.
The issue is that the FastTransformer
uses the __dirname
global variable (see line 74) but this variable is not available in ES Modules (see the Node.js documentation).
Hi,
The plugin was working in 9.3.0, but now it does nothing, only copy the file to destination folder.
I tried to update to 11.0.0, but I got an error:
[19:53:30] Requiring external module esm TypeError [ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING]: A dynamic import callback was not specified. at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:34:9) at eval (eval at <anonymous> (/home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/lib/shared/require-or-import.js:10:15), <anonymous>:3:1) at requireOrImport (/home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/lib/shared/require-or-import.js:24:7) at execute (/home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/lib/versioned/^4.0.0/index.js:37:3) at Liftoff.handleArguments (/home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/index.js:211:24) at Liftoff.execute (/home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/node_modules/liftoff/index.js:201:12) at module.exports (/home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/node_modules/flagged-respawn/index.js:51:3) at Liftoff.<anonymous> (/home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/node_modules/liftoff/index.js:191:5) at /home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/node_modules/liftoff/index.js:149:9 at /home/antonio/.nvm/versions/node/v14.15.3/lib/node_modules/gulp-cli/node_modules/v8flags/index.js:162:14 { code: 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING' }
I tried many times.
node: v14.15.3
npm: 7.5.6
gulp:
CLI version: 2.3.0
Local version: 4.0.2
I'm trying to setup my WordPress site with my current front-end workflow and it seems that I'm having problems with your NPM package, "Cannot find module '@cedx/enum'". When I click the 'gulp' command this error shows up:
module.js:538
throw err;
^
Error: Cannot find module '@cedx/enum'
at Function.Module._resolveFilename (module.js:536:15)
at Function.Module._load (module.js:466:25)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at Object. (/home/mguyromelle/web-projects/vvv/www/joblisting/htdocs/wp-content/themes/joblisting-custom-vue-wp-rest/node_modules/@cedx/gulp-php-minify/lib/transform_mode.js:2:16)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
I need to resolve this as soon as possible. Thanks in advance.
Hallo,
When i try to add your plugin to my gulpfile.js (https://pastebin.com/BvZHP4DY) i get a error.
How i can import your plugin correctly the docs don't have resolved my problem the import not work.
Hi
I'm trying to use gulp-php-minify version 7.1.1, but I get a an error:
spawn C ENOENT
I am using:-
gulp.task('minifyphp', function (cb) {
pump([
gulp.src(SRC + '*.php', {read: false}),
phpMinify({
binary: 'path_to\php\php5.6.35\php.exe'
}),
gulp.dest(DEST + 'php_min')
],
cb
);
});
Error: [@cedx/gulp-php-minify] spawn C ENOENT
at Minifier._transform (C:\Users\rb\Desktop\web_webdev\node_modules@cedx\gulp-php-minify\lib\minifier.js:83:30)
at
at runMicrotasksCallback (internal/process/next_tick.js:121:5)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
Any ideas as to the potential reason for this Error?
Can I also just confirm whether it handles files with combined PHP and HTML content, i.e. that it just minifies within the PHP tags, and just passes through the rest of the HTML untouched.
var gulp = require('gulp');
const phpMinify = require('@cedx/gulp-php-minify');
gulp.task('compress:php', () => gulp.src(["../**/*.php", "!../**/_*.php"], {read: false})
.pipe(phpMinify({binary: 'd:\\OpenServer\\modules\\php\\PHP-5.6-x64\\php.exe'}))
.pipe(gulp.dest("../!RELIZ/" + conf.project_dir_name + "/"))
);
Return:
function phpMinify(options = {}) {
^
SyntaxError: Unexpected token =
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:414:25)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (\npm\gulpfile_relise.js:27:19)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
I am for the first time trying to minify my php code for increase my score in pagespeed by Google.
But I find that error when I require the plugin gulp-php-minify. You can see in code below.
const {phpMinify} = require('@cedx/gulp-php-minify');
I did the same as the example on the plugin page.
/var/www/project-name/node_modules/@cedx/gulp-php-minify/lib/fast_transformer.js:35
async close() {
^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/var/www/project-name/node_modules/@cedx/gulp-php-minify/lib/index.js:7:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
hello, when i use the plugin like this i get the following error in the output in all php files:
i looked at the file
/node_modules/@cedx/php-minifier/www/index.php
In lines 20 and 24 there are incomprehensible lines such as mediaType: and status: they should not be there.
As soon as I removed them, everything began to work immediately! Most likely this is how the IDE added it when publishing :)
config:
npm -V
[email protected] /opt/homebrew/lib/node_modules/npm
node -v
v20.4.0
PHP 7.3.33 (cli) (built: Jul 13 2023 17:29:11) ( NTS )
But that is not all!
when using this plugin, it turns out that the assembly hangs for an unknown reason when it is used with other tasks
Dear author, please correct!
How do i use this plugin?
task code example:
export const php = () => {
return app.gulp.src(app.path.src.php, {read:false})
.pipe(app.plugins.phpMinifier({mode: "fast"}))
.on('error', err => console.log(err))
.pipe(app.gulp.dest(app.path.build.php))
}
I'm running nodejs on a windows pc with gulp v4.0.0 installed.
I have created following gulp-task:
const ejs = require("gulp-ejs");
const fs = require("fs-extra");
const gulp = require("gulp");
const gulpif = require("gulp-if");
const path = require("path");
const { phpMinify } = require('@cedx/gulp-php-minify');
gulp.task(
"Build:PHP",
() => Src(["**/*.php"], { read: false }).pipe(
phpMinify()
).pipe(
gulp.dest("obj/Release")
)
);
When I try to execute this task by invoking npx gulp Build:PHP
I'm receiving following error:
[18:06:14] Using gulpfile D:\Manuel\Dokumente\Projekte\Test\gulpfile.js
[18:06:14] Starting 'Build:PHP'...
[18:06:15] The following tasks did not complete: Build:PHP
[18:06:15] Did you forget to signal async completion?
Please help
gulp
G:\Google-Drive\Web_learning\Website_Files\Workflows\node_modules@cedx\gulp-php-minify\lib\fast_transformer.js:67
async close() {
^^^^^
SyntaxError: Unexpected identifier
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object. (G:\Google-Drive\Web_learning\Website_Files\Workflows\node_modules@cedx\gulp-php-minify\lib\index.js:3:27)
Hello Sir. I got an issue when I applied your library in my current WordPress front-end setup. Here it is:
Error: [@cedx/gulp-php-minify] promisify is not a function
at Minifier._transform (/home/mguyromelle/web-projects/vvv/www/tagumgov/htdocs/wp-content/themes/wp-bootstrap-starter-child/node_modules//lib/minifier.js:94:30)
at runMicrotasksCallback (internal/process/next_tick.js:64:5)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
Hoping for an answer as soon as possible. Im currently working this for a client. Deadline is soon.
None of the documentation url's in your readme work.
This means we do not know how to use your package.
EDIT:
I can see you also did the last commits on this repo:
https://github.com/aquafadas-com/gulp-php-minify/commits/master
which seems similar, so I'll try the implementation noted in the readme there.
EDIT2:
No, can't seem to get it working that way
Thanks
Hello,
When i try to minify my php file, is return the warning and not finish the process.
Thanks
Using gulpfile ~/Projetos/devgranito/build-gulp/gulpfile.js
Starting 'php-minify'...
Minifying: /Users/build-gulp/app/file.php
(node:14716) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: [@cedx/gulp-php-minify] Error: connect ECONNREFUSED 127.0.0.1:8000
Hi, the plugin doesn't return me any error, copy the file in the dest directory but doesn't minify.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.