daku / nette-webpack-manifest
Provides Latte functions for reading asset paths from Webpack manifest file.
Requires
- php: >=8.0
- latte/latte: ^3.0
- nette/application: ^3.1
- nette/di: ^3.0
This package is auto-updated.
Last update: 2024-11-11 02:03:50 UTC
README
This is a simple extension designed to read Webpack assets from a manifest file generated by the webpack-manifest-plugin. It adds two functions, getWebpackAsset()
and hasWebpackAsset()
to Latte templates. This extension only reads values from the manifest file, so you should ensure that the proper path is generated in the manifest file. When debug mode is enabled, assets are always read from the manifest file. When debug mode is disabled, assets are cached in the DI container.
Installation
composer require daku/nette-webpack-manifest
Usage
To use this extension, register it and provide the path to the manifest file in your Neon configuration file:
extensions: webpackManifest: Daku\Nette\Webpack\WebpackManifestExtension('%wwwDir%/static/webpack/manifest.json')
You can then use the getWebpackAsset()
function to retrieve the asset path. If the asset is not found, an exception is thrown. You can also check for the existence of an asset using the hasWebpackAsset()
function:
<link rel="stylesheet" n:if="hasWebpackAsset('app.css')" href="{$basePath}/{getWebpackAsset('app.css')}"> <script n:if="hasWebpackAsset('app.js')" src="{$basePath}/{getWebpackAsset('app.js')}"></script>
Requirements
- PHP >= 8.0
- Nette >= 3