From 301b198ccaf37df4bd8e3c77be787fbd3ffe37c9 Mon Sep 17 00:00:00 2001 From: Muhammad Fahli Saputra Date: Sun, 3 Sep 2023 15:47:28 +0700 Subject: [PATCH 1/2] fix: change typo on config file (minfy to minify) and implement custom prefix for assets route --- config/minify.php | 31 +++++++++++++++++++++-- src/Exceptions/InvalidMinifyException.php | 10 ++++++++ src/Helpers.php | 9 ++++--- src/MinifyServiceProvider.php | 6 ++++- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 src/Exceptions/InvalidMinifyException.php diff --git a/config/minify.php b/config/minify.php index 3aba7ca..52d300b 100644 --- a/config/minify.php +++ b/config/minify.php @@ -24,7 +24,7 @@ | Default: true | */ - 'enabled' => env('MINFY_ENABLED', true), + 'enabled' => env('MINIFY_ENABLED', true), /* |-------------------------------------------------------------------------- @@ -41,7 +41,7 @@ | Default: false | */ - 'assets_enabled' => env('MINFY_ASSETS_ENABLED', false), + 'assets_enabled' => env('MINIFY_ASSETS_ENABLED', false), /* |-------------------------------------------------------------------------- @@ -85,6 +85,33 @@ */ 'obfuscate' => env('MINIFY_OBFUSCATE', true), + /* + |-------------------------------------------------------------------------- + | Route Prefix + |-------------------------------------------------------------------------- + | + | This option allows you to specify a route prefix for the minify route. + | For example, if the route prefix is set to "_minify", then the minify + | route will be accessible at http://example.com/_minify/{hash} + | + | Default: "_minify" + | + */ + 'route_prefix' => env('MINIFY_ROUTE_PREFIX', '_minify'), + + /* + |-------------------------------------------------------------------------- + | Assets Caching + |-------------------------------------------------------------------------- + | + | This option allows you to specify a cache lifetime for the minified + | assets. The default is 1 week. Set to false to disable caching. + | + | Default: 604800 + | + */ + 'cache_lifetime' => env('MINIFY_CACHE_LIFETIME', 604800), + /* |-------------------------------------------------------------------------- | Ignore Routes diff --git a/src/Exceptions/InvalidMinifyException.php b/src/Exceptions/InvalidMinifyException.php new file mode 100644 index 0000000..28a0c20 --- /dev/null +++ b/src/Exceptions/InvalidMinifyException.php @@ -0,0 +1,10 @@ +where('file', '(.*)') ->name('minify.assets'); } From b9342707341149128581fd2865de1577c87ef291 Mon Sep 17 00:00:00 2001 From: Muhammad Fahli Saputra Date: Sun, 3 Sep 2023 15:54:30 +0700 Subject: [PATCH 2/2] feat: create assets directory when publishing assets --- src/MinifyServiceProvider.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/MinifyServiceProvider.php b/src/MinifyServiceProvider.php index 8277355..858922b 100644 --- a/src/MinifyServiceProvider.php +++ b/src/MinifyServiceProvider.php @@ -38,6 +38,9 @@ protected function registerPublishables() $this->publishes([ __DIR__.'/../config/minify.php' => config_path('minify.php'), ], 'config'); + + $this->createAssetDirectory(); + } public function registerConfig() @@ -54,4 +57,19 @@ public function registerRoutes() ->where('file', '(.*)') ->name('minify.assets'); } + + public function createAssetDirectory() + { + $path = base_path('/assets'); + if (!file_exists($path)) { + mkdir($path, 0777, true); + } + + $js = $path . '/js'; + if (!file_exists($js)) { + mkdir($js, 0777, true); + } + + file_put_contents($js . '/example.js', "console.log('Hello World!');"); + } }