diff --git a/src/Assets/Asset.php b/src/Assets/Asset.php index e14459d..77875d3 100644 --- a/src/Assets/Asset.php +++ b/src/Assets/Asset.php @@ -4,8 +4,11 @@ class Asset { - public function __construct(public string $path, public array $dependencies = []) - { + public function __construct( + public string $path, + public array $dependencies = [], + public array|bool|null $args = null + ) { // } @@ -18,4 +21,9 @@ public function dependencies() { return $this->dependencies; } + + public function args(): array|bool|null + { + return $this->args; + } } diff --git a/src/Assets/Compiler.php b/src/Assets/Compiler.php index 4773635..02be056 100644 --- a/src/Assets/Compiler.php +++ b/src/Assets/Compiler.php @@ -33,9 +33,9 @@ public function getEditorStyleFile(): ?string return $this->editorStyleFile; } - public function registerAsset($asset, $dependencies = []): self + public function registerAsset($asset, $dependencies = [], array|bool|null $args = null): self { - $this->assets[$asset] = new Asset(path: $asset, dependencies: $dependencies); + $this->assets[$asset] = new Asset(path: $asset, dependencies: $dependencies, args: $args); return $this; } diff --git a/src/Assets/LaravelMixCompiler.php b/src/Assets/LaravelMixCompiler.php index 1d74007..904601d 100644 --- a/src/Assets/LaravelMixCompiler.php +++ b/src/Assets/LaravelMixCompiler.php @@ -29,7 +29,7 @@ public function enqueueAssets(): void $uri = get_theme_file_uri($manifest[$assetInDist]); if (str_ends_with($asset->path(), '.js')) { - wp_enqueue_script("{$this->handle}-$filename", $uri, $asset->dependencies(), $themeVersion, false); + wp_enqueue_script("{$this->handle}-$filename", $uri, $asset->dependencies(), $themeVersion, $asset->args() ?? false); } elseif (str_ends_with($asset->path(), '.css')) { wp_enqueue_style("{$this->handle}-$filename", $uri, $asset->dependencies(), $themeVersion); } diff --git a/src/Assets/ViteCompiler.php b/src/Assets/ViteCompiler.php index 9d4b934..fb8b25d 100644 --- a/src/Assets/ViteCompiler.php +++ b/src/Assets/ViteCompiler.php @@ -28,13 +28,13 @@ public function ssl(bool $verify = true): self public function isDevServerRunning(): bool { - if(! in_array(wp_get_environment_type(), ['local', 'development'])) { + if (! in_array(wp_get_environment_type(), ['local', 'development'])) { return false; } $args = []; - if($this->ssl) { + if ($this->ssl) { $args['sslverify'] = $this->sslVerify; } @@ -144,7 +144,7 @@ public function enqueueAssets(): void $url = $this->serverUrl.'/'.ltrim($asset->path(), '/'); if (str_ends_with($asset->path(), '.js')) { - wp_enqueue_script("{$this->handle}-$filename", $url, array_merge($asset->dependencies(), ['vite-client']), null, false); + wp_enqueue_script("{$this->handle}-$filename", $url, array_merge($asset->dependencies(), ['vite-client']), null, $asset->args() ?? false); } elseif (str_ends_with($asset->path(), '.css')) { wp_enqueue_style("{$this->handle}-$filename", $url, $asset->dependencies(), null); } @@ -179,7 +179,7 @@ public function enqueueAssets(): void $uri = get_theme_file_uri('dist/'.$file); if (str_ends_with($file, '.js')) { - wp_enqueue_script("{$this->handle}-$filename", $uri, $asset->dependencies(), $themeVersion, true); + wp_enqueue_script("{$this->handle}-$filename", $uri, $asset->dependencies(), $themeVersion, $asset->args() ?? true); } elseif (str_ends_with($file, '.css')) { wp_enqueue_style("{$this->handle}-$filename", $uri, $asset->dependencies(), $themeVersion); }