Coder Social home page Coder Social logo

minify's Introduction

Minify

For laravel 5 please use devfactory/minify

Build Status Latest Stable Version Total Downloads License

With this package you can minify your existing stylessheet and javascript files. This process can be a little tough, this package simplies this process and automates it.

Installation

Begin by installing this package through Composer.

{
    "require": {
    	"ceesvanegmond/minify": "2.0.*"
	}
}

Laravel installation

// app/config/app.php

'providers' => [
    '...',
    'CeesVanEgmond\Minify\MinifyServiceProvider',
];

Publish the config file:

php artisan config:publish ceesvanegmond/minify

When you've added the MinifyServiceProvider an extra Minify facade is available. You can use this Facade anywhere in your application

Stylesheet

// app/views/hello.blade.php

<html>
	<head>
		...
		{{ Minify::stylesheet('/css/main.css') }}
		// or by passing multiple files
		{{ Minify::stylesheet(array('/css/main.css', '/css/bootstrap.css')) }}
		// add custom attributes
		{{ Minify::stylesheet(array('/css/main.css', '/css/bootstrap.css'), array('foo' => 'bar')) }}
		// add full uri of the resource
		{{ Minify::stylesheet(array('/css/main.css', '/css/bootstrap.css'))->withFullUrl() }}

		// minify and combine all stylesheet files in given folder
		{{ Minify::stylesheetDir('/css/') }}
		// add custom attributes to minify and combine all stylesheet files in given folder
		{{ Minify::stylesheetDir('/css/', array('foo' => 'bar', 'defer' => true)) }}
		// minify and combine all stylesheet files in given folder with full uri
		{{ Minify::stylesheetDir('/css/')->withFullUrl() }}
	</head>
	...
</html>

Javascript

// app/views/hello.blade.php

<html>
	<body>
	...
	</body>
	{{ Minify::javascript('/js/jquery.js') }}
	// or by passing multiple files
	{{ Minify::javascript(array('/js/jquery.js', '/js/jquery-ui.js')) }}
	// add custom attributes
	{{ Minify::javascript(array('/js/jquery.js', '/js/jquery-ui.js'), array('bar' => 'baz')) }}
	// add full uri of the resource
	{{ Minify::javascript(array('/js/jquery.js', '/js/jquery-ui.js'))->withFullUrl() }}

	// minify and combine all javascript files in given folder
	{{ Minify::javascriptDir('/js/') }}
	// add custom attributes to minify and combine all javascript files in given folder
	{{ Minify::javascriptDir('/js/', array('bar' => 'baz', 'async' => true)) }}
	// minify and combine all javascript files in given folder with full uri
	{{ Minify::javascriptDir('/js/')->withFullUrl() }}
</html>

Config

<?php

return array(

    /*
    |--------------------------------------------------------------------------
    | App environments to not minify
    |--------------------------------------------------------------------------
    |
    | These environments will not be minified
    |
    */

    'ignore_environments' => array(
	     'local',
    ),

    /*
    |--------------------------------------------------------------------------
    | CSS path and CSS build path
    |--------------------------------------------------------------------------
    |
    | Minify is an extension that can minify your css files into one build file.
    | The css_path property is the location where your CSS files are located
    | The css_builds_path property is the location where the builded files are
    | stored.  This is relative to the css_path property.
    |
    */

    'css_build_path' => '/css/builds/',

    /*
    |--------------------------------------------------------------------------
    | JS path and JS build path
    |--------------------------------------------------------------------------
    |
    | Minify is an extension that can minify your JS files into one build file.
    | The JS_path property is the location where your JS files are located
    | The JS_builds_path property is the location where the builded files are
    | stored.  This is relative to the css_path property.
    |
    */

    'js_build_path' => '/js/builds/',

);

Without Laravel

<?php
$config = array(
	'ignore_environments' => 'local',
	'js_build_path' => '/js/builds/',
	'css_builds_path' => '/css/builds',
)
$minify = new CeesVanEgmond\Minify\Providers\Javascript($public_path);
$minify->add($file)

if (in_array($environment, $config['ignore_environments']))
{
    return $provider->tags();
}

if ( ! $minify->make($config['css_build_path'] ) {
	$filename = $provider->tag($config['css_build_path'] . $provider->getFilename());
}

$provider->minify();

$filename = $provider->tag($config['css_build_path'] . $provider->getFilename());

minify's People

Contributors

amalfra avatar antal-levente avatar atyagi avatar ceesvanegmond avatar jimmyko avatar jorygeerts avatar luizpedone avatar mcordingley avatar mean-cj avatar sirsquall avatar smgladkovskiy avatar spxcxcxxs21-gxst avatar xaockd 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  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  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  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  avatar  avatar  avatar  avatar  avatar  avatar

minify's Issues

Not working in Laravel 4

I am getting this error:

Class 'Minify' not found

Weird thing is that it is installed.

In app.php I have added:

'CeesVanEgmond\Minify\MinifyServiceProvider',

The files are all in the vendor folder...

My code in Blade:

{{ Minify::stylesheet('assets/css/style.css') }}

They say the error is on this line:

<?php echo Minify::stylesheet('assets/css/style.css'); ?>

Is this a new bug in Larevel 4? A problem with composer? It does not make any sense.

I also already did artisan dump-autoload.

I have Laravel 4.

PHP 5.5.10 (cli) (built: Mar 7 2014 08:41:26) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

Using MAMP server.

In app.php I just added:

'Minify'         => 'CeesVanEgmond\Minify\Facades\Minify',

But now I am getting this error:

Call to undefined method CeesVanEgmond\Minify\Facades\Minify::stylesheet()

Laravel 5

Hi, Thanks for the package is great, Elixir is just big, I was wondering, can I install it in L5? Im getting a error adMethodCallException in ServiceProvider.php line 226:
Call to undefined method [package]?

Should I use version 2.0.* or 3.0.*?

Thanks you for you time

Naming Convention

How can i change the naming convention to something simpler like just "style.min.css", because from the look of it, if you have quite a number of files to minify, the eventual name can get really long, really fast

Path is not currect in the website

Sir

Thanks for this good package for laravel. I have some issue with this package. I put public folder and put on the root, so in normal case i use

{{HTML::style('public/css/style.css)}} it work well , but when i use this package i gave

{{Minify::stylesheet('/css/v-front-common.css')}}

Output website become

link href="css/builds/850a53aa7231cd72d94674fb352063081423895179.css" rel="stylesheet"

So style is not loading on the website, actual root

http:://localhost/videoreels/public/css/builds/<--stylesheet name-->

So is there any way to fix this one

When i gibe minift::stylesheet('/public/css/main.css') and ('public/css/main.css') it show error that

E:\MyWork\PHPWork\XAMP\htdocs\videoreels\publicpublic/css/v-front-common.css' does not exist

Paths bug

Hi,

Just wanted to use the bundle in a new project and noticed that an update was released which is good, but the paths isn't for the minifyed files are wrong in case of a subdirectory.

My laravel is located inside a directory on my host (example.com/example/laravel) and the linked files has a path of example.com/path_to_the_files not example.com/example/laravel/path_to_the_files.

Checked the code but theres no option to set this, like in the old versions.

Any suggestion?

gzip files

Would be good to gzip files on-disk instead of making the webserver do it every time it serves a file.

composer failed (satisfiable by natxet/cssmin[3.0.x-dev])

$ php composer.phar require ceesvanegmond/minify:2.0.*

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - ceesvanegmond/minify 2.0 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - ceesvanegmond/minify 2.0.1 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - ceesvanegmond/minify 2.0.2 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - ceesvanegmond/minify 2.0.3 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - ceesvanegmond/minify 2.0.4 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - ceesvanegmond/minify 2.0.5 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - ceesvanegmond/minify 2.0.6 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - ceesvanegmond/minify 2.0.7 requires natxet/cssmin 3.* -> satisfiable by natxet/cssmin[3.0.x-dev].
    - Conclusion: don't install natxet/cssmin 3.0.x-dev
    - Installation request for ceesvanegmond/minify 2.0.* -> satisfiable by ceesvanegmond/minify[2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.0.6, 2.0.7].


Installation failed, reverting ./composer.json to its original content.

Issue with URL

All my js/css are in public folder and i am using {{ Minify::javascript('/js/custom/reminder.js')}} which successfully creating minified file in builds folder but its not included in page. From console i can see url generated by Minify isn't correct. Its coming like below url with 403 error code. I am using laravel 4.1. How i can fix it.

http://localhost/my-project/public/%3Cscript%20src=

Abandonned

Why did you abandon the package ?

If you need some help to maintain the package I will gladly take it over.

@Media CSS entries dropped

When Minifying using the latest package, all @media entries in my CSS are lost when the minification completes. When i inspect the minified version of my CSS the @media rules are gone.

Wrong links are generated when the app isn’t in document root

When I just checked out the web IDE Codio to work on a laravel app, I noticed that my assets weren’t loaded. The reason is that using Codio’s default setup my app is located at http://xy.codio.io:3000/public/, and therefore my (CSS) assets are located at http://xy.codio.io:3000/public/assets/build/css/lots-of-numbers-and-letters.css. However the link generated by minify is http://xy.codio.io:3000/assets/build/css/lots-of-numbers-and-letters.css, i.e. minify doesn’t notice the path of the app. I think this should be fixed. Laravel’s asset() helper function may be of help.

No matching package found

Problem 1 - Installation request for ceesvanegmond/minify dev-master -> satisfiable by ceesvanegmond/minify[dev-master]. - ceesvanegmond/minify dev-master requires natxet/cssmin dev-master -> no matching package found.

Invalid minify?

Hi,

Used your packacge and everything works like a charm but I end with a report from Firebug indicating that the minification is not done correctly. I minified the following js-files:
{{ javascript(array(
'jquery.min.js',
'jquery-ui.min.js',
'bootstrap.min.js'
))
}}

In Firebug that results in the following error:
wrongoperand

Any idea?

Edwin

base_url Not working ?

I'm using minify with laravel in 2 servers, my own local machine where it works ok with a virtual host, and a server with an URL like:

http://111.222.333.444/somefolder/

On this server, minify builds something like

that is not correct because the route is /somefolder/assets....

even when I put 'base_url' configuration.

Something is wrong or am I doing something wrong?

ErrorException in Minifier.php line 476: Unclosed string at position

Minifier should detect if a file is already minified and just include it without minifying it a second time.

Processing an already minified js file sometimes leads to a:

ErrorException in Minifier.php line 476: Unclosed string at position

This is not really an issue with the minify module itself, but with JSshrink and how it's beeing used. The error is thrown in vendor/tedivm/jshrink/src/JShrink/Minifier.php around line 471:

            // New lines in strings without line delimiters are bad- actual
            // new lines will be represented by the string \n and not the actual
            // character, so those will be treated just fine using the switch
            // block below.
            case "\n":
                throw new \RuntimeException('Unclosed string at position: ' . $startpos );
                break;

Doesn't work with multiple libraries

Including jquery-ui-1.10.4.min.js results in 'Invalid left-hand side expression in postfix operation',
including tinymce.min.js results in 'Unexpected token !',
including diff_match_patch.js results in 'Undefined is not a function'

And so on..use Laravel 4.2, JavaScript works error-free without minify.

Call to undefined method CeesVanEgmond\Minify\Minify::stylesheetDir()

I've added this line to providers:

'CeesVanEgmond\Minify\MinifyServiceProvider',

Published configs:
$ php artisan config:publish ceesvanegmond/minify

Use case in my view:
{{ Minify::stylesheetDir('/css/') }}

My composer.json:

{
    "require": {
        "netson/l4gettext": "dev-master",
        "raveren/kint": "dev-master",
        "laravel/framework": "4.0.*",
        "barryvdh/laravel-ide-helper": "1.*",
        "leafo/lessphp": "0.4.*@dev",
        "aws/aws-sdk-php-laravel": "1.*",
        "ceesvanegmond/minify": "2.0.*"
    },
    "autoload": {
        "classmap": [
            "app/commands",
            "app/controllers",
            "app/models",
            "app/forms",
            "app/database/migrations",
            "app/database/seeds",
            "app/tests/TestCase.php",
            "app/library"
        ],
        "psr-0": {
            "Plupload": "app/library/Plupload/"
        }
    },
    "scripts": {
        "pre-update-cmd": [
            "php artisan clear-compiled"
        ],
        "post-install-cmd": [
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "minimum-stability": "stable"
}

Bootstrap glyph icons not working after compression

Whenever I enable the plugin, the glyph icons in Bootstrap display incorrectly as empty boxes. Like the character encoding is changed. Is there a fix?

I just found that the icon fonts are created with the content css attribute, like:

content: "\e001";

Debug mode

Add to config file a var to debug mode and add 2 interesting lines to Minify::javascript and Minify::stylesheet to check if is a debugger environment and return the resource without process.

How to solve background-image final paths

I have this config:

'css_build_path' => '/storage/cache/css/',
'js_build_path' => '/storage/cache/js/',
'base_url' => '/app/www/public/'

And this load:

<?= Minify::stylesheet([
    '/bootstrap/css/bootstrap.min.css',
    '/font-awesome/css/font-awesome.min.css',
    '/fancybox/jquery.fancybox.css',
    '/css/style.css',
    '/css/custom.css'
])->withFullUrl(); ?>

The problem is that all background-image paths to load fonts are not changed, I think that it must be updated using base_url param.

Before:

background-image:url(../images/logo-white.svg)

After:

background-image:url(/app/www/public/images/logo-white.svg)

There are some parameter to do it?

Regards,
Lito.

Config environments not working

Hi in start.php if I return 'local' environment it ignores the minification, if I return 'production' produces minification which is fine.

What doesn't work is if I am in 'local' environment and decide I want to see what the minification looks like and remove 'local' from the ignore_environments, it still produces the raw files, doesn't take the settings into account.

Same visa versa, if I am in 'production' and decide I want to see what the raw files are, and specify in the config to ignore 'production' it still produces the minified version.

Basically nothing I put in the ignore_environments works.

Only way I can make it work and switch between minified and not minified is by specifying 'local' or 'production' in the start.php. Config file does nothing?

Composer failed

ceesvanegmond/minify dev-master requires natxet/cssmin dev-master -> no matching package found.

Please change natxet/CssMin in composer.json to use all lowercase to satisfy composer

wrong requested url

Hi
I add this line to my blade file :
{{ Minify::stylesheet('/css/stylesheets/foundation.min.css') }} instead of {{HTML::style('/css/stylesheets/foundation.min.css')}},and it created a css file in builds folder under public/css, but when I run my page the requested url is localhost/css/builds/somename.css and of course it causes 404 not found error.
what is my fault??
Thank's a lot.

Does't work please check try again.

Does't work please check try again.

{{ Minify::javascript(array(
        '/js/partials/main.js',
    ))
. Minify::stylesheet(array(
        '/assets/bootstrap/css/bootstrap.css',
        '/assets/jquery-ui/css/smoothness/jquery-ui-1.10.4.custom.min.css',
    ))
}}

Output

<link href="/assets/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/assets/jquery-ui/css/smoothness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet">
<link href="/assets/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/assets/jquery-ui/css/smoothness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet">

this work.

{{ Minify::javascript(array(
        '/js/partials/main.js',
    ))
}}
{{ Minify::stylesheet(array(
        '/assets/bootstrap/css/bootstrap.css',
        '/assets/jquery-ui/css/smoothness/jquery-ui-1.10.4.custom.min.css',
    ))
}}

Output

<script src="/js/partials/main.js"></script>
<link href="/assets/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/assets/jquery-ui/css/smoothness/jquery-ui-1.10.4.custom.min.css" rel="stylesheet">

ignore_environments

Hi,

When I use the ignore_environments option, the minified files are still generated. The package just returns the path to the real files (not the minified ones).
I think it would be better when you're on a environment that needs to be ignored, the files are not minified. This is because whenever I change anything in the CSS or Javascript the minified files are re-generated and takes a lot of time.

Problem with javascript compression on my regex

Hi,
composer :
"ceesvanegmond/minify": "2.0.*",
On :
Laravel 4.2

I got an error when i compress my javascript.
In my js code i got :

/(NaN| {2}|^$)/.test(a)

After compressed :

/(NaN|{2}|^$)/.test(a)

Obviously, an error occured ! How can i edit the javascript compression class to correct my situation ?

Thx a lot !

use folders in app path

Hi, i'm interested in use path in app folder, not be stuck on public, so i tried to extend your Minify class and change the methods (javascript / stylesheet, also dir methods) but many methods and variables are private.

i suggest to use realpath so we can add two dots with slash to access the app folder...

by the way, my structure is like app/admin/css, app/admin/js etc and the builds should continue in public path...

Relative img path

in css

background: url(../img/pattern/boxed-pattern1.gif);

will generate:

background: url(../img/pattern/boxed-pattern1.gif);

will compress and saves compressed css inside folder, but path to the images was not corrected.
Here is the config:

'css_build_path' => '/css/builds/',

I think that generated css paths to the static images must be generated as:

background: url(../../img/pattern/boxed-pattern1.gif);

How to deal with relative urls for resources?

Once you minify css and js all the relative urls go to on one file. And many resources e.g. images get linked wrong from your css or js. How do you deal with relative urls for resources? Or u have to edit all urls used in css and js files to be absolute? I have had to manually do that.

Array to String conversion exception

I got an exception when using this library.

Had to change the config calls from using :: to . in helper.php

That is:
From: $path = Config::get('minify::css_path', '/css/');
To: $path = Config::get('minify.css_path', '/css/');

Error withFullUrl

my url : http://localhost/page1/pg/public
i used withFullUrl this call getBaseUrl an this return http:localhost
i replace

return sprintf("%s://%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['HTTP_HOST']
);

for

return \Request::getBaseUrl() // laravel

Call to a member function withFullUrl() on a non-object

I've installed the library and when I want to use it in Laravel I got the error:

Call to a member function withFullUrl() on a non-object

If I remove the withFullUrl() method I got a link but is wrong pointed to my /public Laravel's path.

Who is wrong, the documentation or me?

Regards

Only return url

Hi

It would be great if a method exists that only returns the URL of the minified file instead of a pre filled HTML element.

This way CDN fallbacks may be defined while still pointing to a minified local version, e.g:

{{ HTML::script('//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js') }}
<script>!window.jQuery && document.write(unescape('%3Cscript src="URL HERE"%3E%3C/script%3E'))</script>

(I know jQuery can be downloaded already minified but this is just an example)

Exception

I get an Exception when trying to use this package.

File:
public/html/vendor/ceesvanegmond/minify/src/CeesVanEgmond/Minify/Minify.php

Error:

$filetime = 0;

foreach ($this->files as $file) {
  $absolutefile = $this->path . $file;
  if (!\File::exists($absolutefile)) {
    throw new \Exception;
  }

Could you help me to sort out what causes this issue, please?
Thanks.

Laravel 5.1

when adding this to providers

CeesVanEgmond\Minify\MinifyServiceProvider::class,

i get this error

BadMethodCallException in ServiceProvider.php line 234:
Call to undefined method [package]

Getting an error

After following your instructions and then doing:

php artisan config:publish ceesvanegmond/minify

I'm getting the error:

PHP Fatal error:  Class 'CeesVanEgmond\Minify\MinifyServiceProvider' not found in /var/www/laravel/bootstrap/compiled.php on line 4485

{"error":{"type":"Symfony\Component\Debug\Exception\FatalErrorException","message":"Class 'CeesVanEgmond\Minify\MinifyServiceProvider' not found","file":"/var/www/laravel/bootstrap/compiled.php","line":4485}}

What do I have to do to solve this issue?

C-style JavaScript comments without a line break at the end of a file...

...break the minified version when prepended to another file.

I've had this issue with qtip.min.js:

/* qTip2 v2.2.1 | Plugins: tips viewport imagemap svg modal ie6 | Styles: core basic css3 | qtip2.com | Licensed MIT | Sat Sep 06 2014 18:25:06 */

!function(a,b,c){/* Their code here... */}(window,document);
//# sourceMappingURL=//cdn.jsdelivr.net/qtip2/2.2.1//var/www/qtip2/build/tmp/tmp-656464emu9s/jquery.qtip.min.map

They're missing a trailing line break (which is ok), but when you combine it to other files and minify, the output is broken – the first line of code from the next file is missing. I think we should simply "sanitize" input files by adding a trailing line break if missing. Any objection?

Minify Wrong URL SHOWING

I have installed the package as you provided, but when i add {{ Minify::stylesheet('/css/main.css') }} in my header.blade.php below error occured, please clarify.

File 'E:\xampp\htdocs\topcutie/css/main.css' does not exist (View: E:\xampp\htdocs\topcutie\app\views\layouts\master.blade.php)

customize final URL

¡Great! ¡Works fine!

But I have several questions:

¿How can I customize final URL? I woud like to add this string "?v=32654" to the final of the URL.

The builds are created in every runtime? Can I created statically in production?

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.