daku/nette-webpack-manifest

Provides Latte functions for reading asset paths from Webpack manifest file.

dev-master 2023-11-11 00:02 UTC

This package is auto-updated.

Last update: 2024-04-11 00:51:49 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