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 @@ +publishes([ __DIR__.'/../config/minify.php' => config_path('minify.php'), ], 'config'); + + $this->createAssetDirectory(); + } public function registerConfig() @@ -46,8 +50,26 @@ public function registerConfig() public function registerRoutes() { - RouteFacade::get('/_minify/{file?}', HttpConnectionHandler::class) + // get the route prefix from the config file + $prefix = config('minify.route_prefix', '_minify'); + + RouteFacade::get('/' . $prefix . '/{file?}', HttpConnectionHandler::class) ->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!');"); + } }