diff --git a/components/asset.rst b/components/asset.rst index 2fdfc8d517a..f541048e7e4 100644 --- a/components/asset.rst +++ b/components/asset.rst @@ -139,6 +139,33 @@ string as the second argument of the ``StaticVersionStrategy`` constructor:: echo $package->getUrl('image.png'); // result: v1/image.png +JSON File Manifest +.................. + +A popular strategy to manage asset versioning, which is used by tools such as +`Webpack`_, is to generate a JSON file mapping all source file names to their +corresponding output file: + +.. code-block:: json + + // rev-manifest.json + { + "css/app.css": "build/css/app.b916426ea1d10021f3f17ce8031f93c2.css", + "js/app.js": "build/js/app.13630905267b809161e71d0f8a0c017b.js", + "...": "..." + } + +In those cases, use the +:class:`Symfony\\Component\\Asset\\VersionStrategy\\JsonManifestVersionStrategy`:: + + use Symfony\Component\Asset\Package; + use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy; + + $package = new Package(new JsonManifestVersionStrategy(__DIR__'./rev-manifest.json')); + + echo $package->getUrl('css/app.css'); + // result: build/css/app.b916426ea1d10021f3f17ce8031f93c2.css + Custom Version Strategies ......................... @@ -349,3 +376,4 @@ Learn more ---------- .. _Packagist: https://packagist.org/packages/symfony/asset +.. _`Webpack`: https://webpack.js.org/ diff --git a/frontend/encore/versioning.rst b/frontend/encore/versioning.rst index 9ba5442ef2c..1846a1507a0 100644 --- a/frontend/encore/versioning.rst +++ b/frontend/encore/versioning.rst @@ -59,3 +59,8 @@ like normal: + +Learn more +---------- + +* :doc:`/components/asset`