Generate minified CSS/JS in the Docker build, remove unused assets
- New 'assets' stage in the Dockerfile builds style.min.css and functions.min.js from the sources (npm run build:min); they are no longer committed, so they can't go stale anymore - Production (APP_DEBUG off) loads the minified files, local development the readable ones, both with a cache-busting version (AssetHelper, Asset::url() in the layout) - Source maps are excluded from the image - Remove unused assets: public/css/old, public/js/old and unused copies of jQuery, wavesurfer, prettyPhoto (min) and mediaplayer_with_plugins - npm scripts: build:css (committed CSS), build:min (Docker build); sass-minify scripts removed - readme: how the CSS/JS build works Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b399e8bc76
commit
f7b1dbac8f
83 files changed
+72
-17741
No files matched your search
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
/**
|
||||
* URLs for our own CSS/JS with cache busting.
|
||||
*
|
||||
* In production (APP_DEBUG off) the minified version is used when it exists:
|
||||
* style.min.css and functions.min.js are generated by the Docker build
|
||||
* (`npm run build:min`) and are not in git. Locally (APP_DEBUG on, or no
|
||||
* .min file) the normal, readable file is used, so source maps keep working.
|
||||
*/
|
||||
class AssetHelper
|
||||
{
|
||||
public static function url(string $path): string
|
||||
{
|
||||
$path = ltrim($path, '/');
|
||||
|
||||
if (!config('app.debug')) {
|
||||
$min = preg_replace('/\.(css|js)$/', '.min.$1', $path);
|
||||
if ($min !== $path && file_exists(public_path($min))) {
|
||||
$path = $min;
|
||||
}
|
||||
}
|
||||
|
||||
$file = public_path($path);
|
||||
$version = file_exists($file) ? filemtime($file) : null;
|
||||
|
||||
return '/' . $path . ($version ? '?' . $version : '');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user