Skip to content

inigopascall/webpack-php-asset-versioning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
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

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published