Code Monkey home page Code Monkey logo

minify's Introduction

Minify

Build Status Latest Stable Version Total Downloads License

With this package you can minify your existing stylesheet and JavaScript files for Laravel 10. This process can be a little tough, this package simplifies and automates this process.

For Laravel 5 - 9 please use version 1.x of this package.

For Laravel 4 please use ceesvanegmond/minify

Installation

Begin by installing this package through Composer.

{
    "require": {
        "devfactory/minify": "^2.0"
    }
}

After the package installation, the MinifyServiceProvider and Minify facade are automatically registered. You can use the Minify facade anywhere in your application.

To publish the config file:

php artisan vendor:publish --provider="Devfactory\Minify\MinifyServiceProvider" --tag="config"

Upgrade to v2

Minify version 2 is PHP 8.1+ and Laravel 10+ only.

Required upgrade changes

If the Devfactory\Minify\Contracts\MinifyInterface interface is implemented, make sure update your implementation according to the updated types and exceptions.

If the Devfactory\Minify\Providers\BaseProvider abstract class is used, make sure update your classes according to the updated types and exceptions.

The method Devfactory\Minify\Providers\StyleSheet#urlCorrection has been renamed to Devfactory\Minify\Providers\StyleSheet#getFileContentWithCorrectedUrls.

Rename the minify.config.php configuration file to minify.php.

Usage

Stylesheet

// app/views/hello.blade.php

<html>
    <head>
        ...
        {!! Minify::stylesheet('/css/main.css') !!}
        // or by passing multiple files
        {!! Minify::stylesheet(['/css/main.css', '/css/bootstrap.css']) !!}
        // add custom attributes
        {!! Minify::stylesheet(['/css/main.css', '/css/bootstrap.css'], ['foo' => 'bar']) !!}
        // add full uri of the resource
        {!! Minify::stylesheet(['/css/main.css', '/css/bootstrap.css'])->withFullUrl() !!}
        {!! Minify::stylesheet(['//fonts.googleapis.com/css?family=Roboto']) !!}

        // 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/', ['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(['/js/jquery.js', '/js/jquery-ui.js']) !!}
    // add custom attributes
    {!! Minify::javascript(['/js/jquery.js', '/js/jquery-ui.js'], ['bar' => 'baz']) !!}
    // add full uri of the resource
    {!! Minify::javascript(['/js/jquery.js', '/js/jquery-ui.js'])->withFullUrl() !!}
    {!! Minify::javascript(['//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js']) !!}

    // 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/', ['bar' => 'baz', 'async' => true]) !!}
    // minify and combine all javascript files in given folder with full uri
    {!! Minify::javascriptDir('/js/')->withFullUrl() !!}
</html>

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.