Git Product home page Git Product logo

asset-php's Introduction

EasyBib\Asset

Prefixing files with a content MD5, as a composer script.

Does

  • copy any file you want to a [content-md5]-original-file-name.ext file
  • provide that filename to your app

Does Not

  • do anything else to your files (no minification, no nothing)

Setup/Usage

$ composer require easybib/asset-php 1.\*

composer

The script exposes two composer "scripts" - EasyBib\\Asset::run and EasyBib\\Asset::clear. You'll also need to add the configuration to your composer.json.

For example:

    "config": {
        "asset": {
            "/js/main.js": {"from": "frontend/src", "to": "frontend/dist"},
            "/css/main.css": {"from": "web/css", "to": "web/css"}
        }
    },
    "scripts": {
        "build": "EasyBib\\Asset::run"
    },

The config.asset syntax is as follows:

    "the name you call Asset::path() with" => {from: "source directory", to: "target directory"}

You can choose other script names, of course. Composer also has some magic script names that it triggers automatically.

app

In your app, replace the path to the file with a call to EasyBib\Asset::path.

For example, with the above configuration, the following

    <script src="<?php EasyBib\\Asset::path('/js/main.js'); ?>"></script>

Will expand into

    <script src="/js/123abcdwhatever-main.js"></script>

once you ran composer build.

To make it fall-back to the source file, you can run EasyBib\Asset::clear(). But because of how the APC works in PHP, you'll have to run that from within the app (or at least using the same SAPI).

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.