crypto_scythe / bundledassets
A Laminas view helper for adding JavaScript and CSS assets created by bundlers
1.0.3
2021-09-07 20:05 UTC
Requires
- php: ^7.4|~8.0
- ext-json: *
- laminas/laminas-config-aggregator: ^1.5
- laminas/laminas-escaper: ^2.8
- laminas/laminas-servicemanager: ^3.7
- laminas/laminas-view: ^2.12
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
This package is auto-updated.
Last update: 2025-02-08 03:40:23 UTC
README
A Laminas view helper for adding JavaScript and CSS assets created by bundlers.
Installation
Composer
composer require crypto_scythe/bundledassets
Manual
You can download the latest release zip file and unpack it into a own module folder. Please make sure to install the dependencies outlined in the composer.json for it to work correctly.
Usage/Examples
Laminas MVC
# Add module class to Modules configuration CryptoScythe\BundledAssets\Module::class,
Laminas Mezzio
# Add config provider class to configuration CryptoScythe\BundledAssets\ConfigProvider::class,
Configuration
# global.php use CryptoScythe\BundledAssets\ConfigProvider as BundledAssetsConfigProvider; BundledAssetsConfigProvider::GLOBAL_CONFIG_KEY_VIEW_HELPER_CONFIG => [ BundledAssetsConfigProvider::class => [ BundledAssetsConfigProvider::CONFIG_KEY_CACHE_PATH => 'data/bundled_assets_cache.php', # Path to cache file, mostly production BundledAssetsConfigProvider::CONFIG_KEY_MANIFESTS => [ # Hash map of manifest files BundledAssetsConfigProvider::CONFIG_KEY_DEFAULT_MANIFEST => 'data/webpack-assets.json', 'other_manifest' => 'data/other-assets.json', # [optional] You can use multiple asset manifests ], ], ],
Usage in layout
$this->bundledAssets('entry_point'); # Uses assets from default $this->bundledAssets('some_other_entry_point', 'other_manifest'); # Uses additionally defined manifest
FAQ
What is a manifest file?
A manifest file contains a list of the bundled assets, for example the output of assets-webpack-plugin.
It looks something like this:
{ "main": { "js": [ "some_js_asset.12345.js", "some_other_js_asset.54321.js" ], "css": [ "some_css_asset.12345.css", "another_css_asset.abcdef.css" ], }, "another": { # even more of the same } }
Author
- Chris Fasel @crypto-scythe