2017 © Pedro Peláez
 

craft-plugin craft-asset-bundler

Provides a console command to publish web/cpresources

image

fortrabbit/craft-asset-bundler

Provides a console command to publish web/cpresources

  • Thursday, June 28, 2018
  • by ostark
  • Repository
  • 2 Watchers
  • 5 Stars
  • 253 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 3 Versions
  • 533 % Grown

The README.md

Deprecated since craftcms/cms: 3.0.13 (2018-06-26)

The plugin is not needed anymore. In Craft 3.0.4 the way cpresources are published was changed. In Craft 3.0.13 another fix was released to change thumbnail delivery in the CP as well., (*1)

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., (*2)

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., (*3)

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

  • (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., (*5)

Usage

Use this command in your build process before you distribute your code to all servers:, (*6)

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:, (*7)

"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., (*8)

TODOs

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

The Versions

28/06 2018

dev-master

9999999-dev

Provides a console command to publish web/cpresources

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft asset-bundle cpresource

12/04 2018

0.6.0

0.6.0.0

Provides a console command to publish web/cpresources

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft asset-bundle cpresource

10/04 2018

0.5.0

0.5.0.0

Provides a console command to publish web/cpresources

  Sources   Download

MIT

The Requires

 

cms craftcms craft-plugin craft asset-bundle cpresource