A simple Webpack plugin to produce a php class with the timestamp of each build; used to 'version' your asset files for cache-busting
npm install --save-dev webpack-asset-versioning
const AssetVersioning = require('webpack-php-asset-versioning');
plugins: [
// ...
new AssetVersioning({
// options
})
]
- file_name the full path of the outputted php file
- class_name the name of the php class
Key | Determines | Default |
---|---|---|
file_name | the full path of the outputted php file | ./assets.version.php |
class_name | the name of the php class | AssetsVersion |
plugins: [
new AssetVersioning({
file_name: '../assets.version.php',
class_name: 'BuildDate'
})
]
assets.version.php
:
<?php
class BuildDate {
public $current = 1562363854500;
}
include_once 'assets.version.php';
$assets_version = (new \AssetsVersion())->current;
(I prefer to use a custom Webpack configuration rather than Laravel Mix. Thus I can include this in my app by loading within AppServiceProvider.php
):
public function boot()
{
include_once base_path() . '/assets.version.php';
$assets_version = (new \AssetsVersion())->current;
View::share('assets_version', $assets_version);
}