Giter VIP home page Giter VIP logo

ejetar-laravel-mix-php-function's Introduction

Laravel Mix PHP Function

About

A lightweight and simple library that adds Laravel Mix's mix() function to your PHP project ๐Ÿš€

You can now use the mix() function of Laravel Mix independently, without needing Laravel and/or Blade and/or Vue...

Installation

composer require ejetar/laravel-mix-php-function

Get started

  1. Load the composer into your project;
  2. Call mix() at the desired location;
  3. And that's it, that's all, have fun!

Example

Let's say we have the following mix-manifest.json, in the public folder of our project:

{
    "/css/all.css": "/css/all.css?id=2fcc406cf38a7867b239",
    "/css/all.min.css": "/css/all.min.css?id=2fcc406cf38a7867b239", 
    "/js/all.js": "/js/all.js?id=2c80a6c15449d3e693ed", 
    "/js/all.min.js": "/js/all.min.js?id=2c80a6c15449d3e693ed"
}

Now suppose I want to retrieve the versioned URL from the /css/all.min.css file:

<?php require_once 'vendor/autoload.php'; //Load Composer ?><!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Example</title>
        
        <link rel="stylesheet" href="<?= mix('/css/all.min.css'); ?>">
        <!-- The result will be /css/all.min.css?id=2fcc406cf38a7867b239 -->
    </head>
    <body>
        <h1>\o/</h1>
    </body>
</html>

That simple!

Custom Mix Base URLs

You can also use custom mix base URLs, just as you would with Laravel.

Just define the constant MIX_ASSET_URL before using the mix function.

Example

<?php
require_once 'vendor/autoload.php'; //Load Composer
define('MIX_ASSET_URL', 'https://cdn.example.com');
?><!doctype html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Example</title>
        
        <link rel="stylesheet" href="<?= mix('/css/all.min.css'); ?>">
        <!-- The result will be https://cdn.example.com/css/all.min.css?id=2fcc406cf38a7867b239 -->
    </head>
    <body>
        <h1>\o/</h1>
    </body>
</html>

Changelog

Nothing for now...

Contributing

Contribute to this wonderful project, it will be a pleasure to have you with us. Let's help the free software community. You are invited to incorporate new features, make corrections, report bugs, and any other form of support. Don't forget to star in this repository! ๐Ÿ˜€

License

This library is a open-source software licensed under the MIT license.

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.