Julien Mariller.ch

Web Developer passionate about standards

Integrate Laravel Mix in Symfony

As part of the compilation of web resources (JavaScript, CSS, etc.), Laravel Mix is an excellent Webpack-based tool with a smooth and easy-to-use interface.

For long-term caching, Laravel Mix offers the mix.version() method which automatically generates an alphanumeric code (hashcode) for each resource and generates the manifest file mix-manifest.json.

Laravel users have at their disposal a global Blade function called mix which takes as parameter the name of the resource (e.g. app.js) and adds its unique code (e.g. app.js?id=0441ad4f65d54589aea5)

With Symfony the equivalent function is asset. For it to work with Laravel Mix, however, an important change must be made in the configuration file framework.yaml of Symfony:

framework:
  # ...
  assets:
    json_manifest_path: '%kernel.project_dir%/public/mix-manifest.json'
  # ...

It is also important to adjust the public path in Laravel Mix with the command mix.setPublicPath('public').

Published on 06/12/2021