Skip to content

Commit

Permalink
changelog + readme for plugin usage
Browse files Browse the repository at this point in the history
  • Loading branch information
passchn committed Oct 30, 2023
1 parent 24ba6c5 commit 5d9ea4e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?php $this->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:
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ViteHelperConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/ViteManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 5d9ea4e

Please sign in to comment.