Giter Site home page Giter Site logo

cedx / php-minifier Goto Github PK

View Code? Open in Web Editor NEW
26.0 6.0 7.0 2.75 MB

Minify PHP source code by removing comments and whitespace.

Home Page: https://docs.belin.io/php-minifier/

License: MIT License

JavaScript 92.44% PHP 7.17% PowerShell 0.40%
gulp php javascript

php-minifier's Introduction

php-minifier's People

Contributors

cedx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

php-minifier's Issues

ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING

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

Doesn't minify php files

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?

UnhandledPromiseRejectionWarning

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

async close() issue

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)

PHP minify is not working

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)

SyntaxError: Unexpected token {

Hello!

I'm getting this error when running the gulp task:

Screenshot_1

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'))
);

Task Doesn't Seem to Complete

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?

Error: [@cedx/gulp-php-minify] promisify is not a function

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.

Parse error, file error /node_modules/@cedx/php-minifier/www/index.php

hello, when i use the plugin like this i get the following error in the output in all php files:


Parse error: syntax error in /Users/**/**/**/**/node_modules/@cedx/php-minifier/www/index.php on line 20

i looked at the file

/node_modules/@cedx/php-minifier/www/index.php

image

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))
}

Cannot find module '@cedx/enum'

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.

Struggling with CommonJS Implementation

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?

SyntaxError: Unexpected token

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)

Import Problem

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.

Error when spawning a custom PHP executable: ENOENT

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.

Error on `require` when using Node.js pre-7.6

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)

Task never defined: default

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:

  1. Example:
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'))
);
  1. Variation according to implementation:
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

Not minify

Hi, the plugin doesn't return me any error, copy the file in the dest directory but doesn't minify.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.