This plugin adds a helper function to Twig to read the Manifest ID that is generated by Laravel Mix when compiling assets. This makes sure than your cache is busted when you update your assets.
Read Mix Manifest with Twig Function
This little plugin reads the Mix Manifest that is generated by the standalone version of Laravel Mix.
Setup
In order to use this plugin you will need set up Laravel Mix (duh!) and enable the versioning in the webpack.mix.js
.
This plugin depends on several config fields, which should be set correctly. Most of the properties should already be correct when left default, but you should definetely set your app url correctly. You can find this property in the config/app.php
file.
The next step is set up your env
file and add the MANIFEST_PATH
field to your env
file. This entry needs to points directly to the manifest file in your project.
How to use
After installing this plugin you can call getVersionedCss()
in Twig. This function takes one parameter which should be the relative path to the file from inside your assets
folder.
<link rel="stylesheet" href="{{ getVersionedCss('/dist/app.css') }}">
Advanced usage
Without a second parameter the getVersionedCss
function assumes that your relative path starts at themes/{themename}/assets
. If your assets are located elsewhere you can pass a second parameter to the function which replaces the standard "/assets"
path prefix.
Note: The /
before the actual path is required for this to work
<link rel="stylesheet" href="{{ getVersionedCss('/dist/app.css' , '/my-assets-path') }}">
Setting up Laravel Mix
This plugin is based on a front-end workflow based on Jeffrey Way's standalone Laravel Mix that can be found here. An example of a package.json
and webpack.mix.js
are also present in this repository. Further documentation on how to use Laravel Mix can be found in the docs of Laravel Mix.
License
While there isn't much to license, we'd appreciate it if you do not sell the plugin or the code in it as your own, either under a new name or as part of your own plugin.
-
Ompmega
Found the plugin useful on 7 Dec, 2018
Thank you for this!
Ended up editing plugin code to replace
getVersionedCss
with justmix
since I'm working with assets other than CSS. -
Luis Medina
Found the plugin useful on 26 Nov, 2018
Does what it promises.
But i think
getVersion
should be a better function name, ormix
like on Laravel, just because this looks a bit odd:getVersionedCss('/dist/js/app.js')
. -
1.1.0 |
Replace getVersionedCss method in favor of Mix May 17, 2019 |
---|---|
1.0.2 |
Load theme directory from Theme class instead of Config Oct 24, 2018 |
1.0.1 |
First version of Mix Manifest Oct 23, 2018 |