1.0.3 • Published 5 years ago

webpack-php-asset-versioning v1.0.3

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

Webpack Asset Versioning - Inigo Pascall

A simple Webpack plugin to produce a php class with the timestamp of each build; used to 'version' your asset files for cache-busting

Usage

Install :

npm install --save-dev webpack-asset-versioning

Configure webpack.config.js

Import:

const AssetVersioning = require('webpack-php-asset-versioning');

Configure plugin:

    plugins: [
		// ...
        new AssetVersioning({
            // options
        })
    ]

Set options:

  • file_name the full path of the outputted php file
  • class_name the name of the php class
KeyDeterminesDefault
file_namethe full path of the outputted php file./assets.version.php
class_namethe name of the php classAssetsVersion

eg:

    plugins: [
        new AssetVersioning({
            file_name: '../assets.version.php',
            class_name: 'BuildDate'
        })
    ]

Produces

assets.version.php :

<?php

class BuildDate {
	public $current = 1562363854500;
}

Include in your php app

include_once 'assets.version.php';
$assets_version = (new \AssetsVersion())->current;

Laravel

(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);
    }
1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago