Giter Club home page Giter Club logo

craft-asset-bundler's Introduction

AssetBundler plugin for Craft CMS 3.x

The plugin provides a console command to publish web/cpresources. This is useful in "cloud environments" like fortrabbit's Professional Stack or when using multiple Dynos on Heroku.

The purpose of this command is to publish AssetBundles files in a publicly accessible /web directory. This happens already on-the-fly, e.g when you access Craft's control panel in the browser the first time. However, in load balanced environments, it happens that files do not exist on all servers after you deployed.

Craft also stores thumbnails of Volume Assets in web/cpresources to make them accessible in the control panel. The plugin changes this behaviour:

  • (default pattern) web/cpresources/{hash}/thumb-{width}x{height}.{ext}?v={modified_date}
  • (modified pattern) web/t/{asset_id}/thumb-{width}x{height}.{ext}?v={modified_date}

This way we can create thumbnails on-the-fly if they don't exist on a certain server.

Usage

Use this command in your build process before you distribute your code to all servers:

php craft asset-bundler/publish

When composer install is part of your deployment process anyways, you can include the command in your composer.json to run it automatically:

"scripts": {    
    "post-install-cmd": [
      "@php craft install/plugin asset-bundler",
      "@php craft asset-bundler/publish"
    ]
  }

How it works

  • All AssetBundle classes that exist in the composer autoload class map get registered.
  • In a /web/cpresources.rev file the timestamp of the latest revision is stored
  • Files are located in web/cpresources/{revision}/{hash}/file.ext
  • {revision} only changes if file is modified

Edge cases

The craft\web\AssetManager::getPublishedUrl() method allows to publish single files that are not part of an AssetBundle. As the plugin is not aware of these files, you may need to add them to a bundle.

TODOs

  • Config option to include additional classes
  • Config option to exclude classes form class map

craft-asset-bundler's People

Contributors

ostark avatar timkelty avatar

Watchers

 avatar  avatar

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.