From 5d9ea4e92963e61eee01fe3cda26cb513a49b93d Mon Sep 17 00:00:00 2001 From: passchn <77938819+passchn@users.noreply.github.com> Date: Mon, 30 Oct 2023 22:30:05 +0100 Subject: [PATCH] changelog + readme for plugin usage --- CHANGELOG.md | 7 +++++++ README.md | 20 ++++++++++++++++++++ src/Utilities/ViteHelperConfig.php | 2 +- src/Utilities/ViteManifest.php | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e68f3a8..d3f7370 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v2.3.0 + +### Changed + +* An instance of `ViteHelperConfig` can now be initialized only with a config key (`string`) +* The `ViteScriptsHelper` accepts `string` for the `$config` argument + ## v2.2.0 ### Added diff --git a/README.md b/README.md index 7f6de2c..4aae38d 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,26 @@ code-splitting and don't use dynamic imports in js. It depends on your project and use case how you define entries. If you don't use `prodFilter` or `files`, the plugin will serve all your entry files which might just be the case you want. So don't overconfigure it ;) +## Opt out of global config + Plugin development + +You can use the helper methods with multiple configurations through the `$config` argument. + +> **New in version 2.3:** You can pass a config key instead of a config instance to the helper. The default config key +> is `ViteHelper`. + +This might be useful when using plugin scripts or when developing plugins: + +```php +ViteScripts->pluginScript('MyPlugin', devMode: true, config: 'MyPlugin.ViteConfig'); ?> +``` + +The example above uses a convenience method to load plugin scripts for `MyPlugin`. DevMode is enabled and the helper +will use a CakePHP config under the key `MyPlugin.ViteConfig`. In this way, you can scope your App's and your plugin's +config. + +It is assumed that the `manifest.json` is available directly in your plugin's `webroot`. If this is not the case, you +should define the absolute path throuh the `build.manifest` config option. + ## Vite JS bundler / Dev server Install Vite e.g. via yarn: diff --git a/src/Utilities/ViteHelperConfig.php b/src/Utilities/ViteHelperConfig.php index b5ebce5..81ae6d8 100644 --- a/src/Utilities/ViteHelperConfig.php +++ b/src/Utilities/ViteHelperConfig.php @@ -21,7 +21,7 @@ public function __construct(array|string|null $config = null) $config = self::DEFAULT_CONFIG_KEY; } - $this->config = is_array($config) ? $config : Configure::readOrFail($config); + $this->config = is_array($config) ? $config : (array)Configure::read($config); } /** diff --git a/src/Utilities/ViteManifest.php b/src/Utilities/ViteManifest.php index 6f0106e..9b826b5 100644 --- a/src/Utilities/ViteManifest.php +++ b/src/Utilities/ViteManifest.php @@ -15,7 +15,7 @@ class ViteManifest * Returns the manifest records as a Collection * * @param \ViteHelper\Utilities\ViteHelperConfig $config plugin config instance - * @return \ViteHelper\Utilities\ManifestRecords|array<\ViteHelper\Utilities\ManifestRecord> + * @return \ViteHelper\Utilities\ManifestRecords<\ViteHelper\Utilities\ManifestRecord> * @throws \ViteHelper\Exception\ManifestNotFoundException * @internal */