Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.1 Under development
## 0.2.0 Under development

- docs: add `Next steps` section with links to installation, usage, configuration, and testing guides.
- docs: update badge in `README.md` to reflect security checks.
- feat!: add `Vite::create()` and replace high-arity render-option and manifest-chunk construction with fluent immutable APIs.

## 0.1.0 August 24, 2026

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
## Installation

```bash
composer require php-forge/vite:^0.1
composer require php-forge/vite:^0.2
```

HTML output is generated with [`ui-awesome/html`](https://github.com/ui-awesome/html) while asset resolution remains
Expand All @@ -64,7 +64,7 @@ use PHPForge\Vite\Configuration\DevelopmentConfiguration;
use PHPForge\Vite\Html\HtmlRenderer;
use PHPForge\Vite\Vite;

$vite = new Vite(
$vite = Vite::create(
new DevelopmentConfiguration(
devServerUrl: 'http://localhost:5173',
),
Expand All @@ -81,7 +81,7 @@ use PHPForge\Vite\Configuration\ProductionConfiguration;
use PHPForge\Vite\Html\HtmlRenderer;
use PHPForge\Vite\Vite;

$vite = new Vite(
$vite = Vite::create(
new ProductionConfiguration(
manifestPath: '/srv/app/public/build/.vite/manifest.json',
assetBaseUrl: '/build',
Expand Down Expand Up @@ -112,7 +112,7 @@ echo (new HtmlRenderer())->render($vite->resolve());
[![Codecov](https://img.shields.io/codecov/c/github/php-forge/vite.svg?style=for-the-badge&logo=codecov&logoColor=white&label=Coverage)](https://codecov.io/gh/php-forge/vite)
[![PHPStan Level Max](https://img.shields.io/badge/PHPStan-Level%20Max-4F5D95.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.com/php-forge/vite/actions/workflows/static.yml)
[![Quality](https://img.shields.io/github/actions/workflow/status/php-forge/vite/quality.yml?style=for-the-badge&label=Quality&logo=github)](https://github.com/php-forge/vite/actions/workflows/quality.yml)
[![Dependency Check](https://img.shields.io/github/actions/workflow/status/php-forge/vite/dependency-check.yml?style=for-the-badge&label=Dependency%20Check&logo=github)](https://github.com/php-forge/vite/actions/workflows/dependency-check.yml)
[![StyleCI](https://img.shields.io/badge/StyleCI-Passed-44CC11.svg?style=for-the-badge&logo=github&logoColor=white)](https://github.styleci.io/repos/1342863441?branch=main)

## Social networks

Expand Down
18 changes: 12 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ strings, fragments, and non-HTTP schemes are rejected.
```php
use PHPForge\Vite\Vite;

$vite = new Vite(
$vite = Vite::create(
configuration: $configuration,
entrypoints: ['resources/js/app.js'],
);
Expand All @@ -59,6 +59,9 @@ $pageAssets = $vite->resolve('resources/js/admin.js');
$combinedAssets = $vite->resolve(['resources/js/app.js', 'resources/js/admin.js']);
```

`Vite::create()` is an additive construction shortcut. The public constructor remains available for dependency-injection
containers and accepts the same arguments.

Default entrypoints belong to the facade because they apply equally to development and production. Duplicate entrypoints
are removed while preserving the first occurrence. At least one entrypoint must be available when `Vite::resolve()` is
called.
Expand Down Expand Up @@ -97,14 +100,17 @@ use PHPForge\Vite\Html\HtmlRenderOptions;

$html = (new HtmlRenderer())->render(
$vite->resolve(),
new HtmlRenderOptions(
nonce: $nonce,
moduleScriptAttributes: ['crossorigin' => true],
stylesheetAttributes: ['media' => 'screen'],
),
HtmlRenderOptions::create()
->withNonce($nonce)
->withModuleScriptAttributes(['crossorigin' => true])
->withStylesheetAttributes(['media' => 'screen']),
);
```

`HtmlRenderOptions::create()` starts with the default policy. Use `withNonce()`, `withSeparator()`, the four per-asset
attribute modifiers, and `withAttributeProvider()` to replace individual values. Every modifier returns a new policy and
leaves the original instance unchanged.

`HtmlRenderer` maps the neutral asset objects to `ui-awesome/html` `Script` and `Link` elements. Applications that consume
`AssetCollection` directly do not depend on the renderer's markup structure.

Expand Down
6 changes: 3 additions & 3 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $configuration = $isDevelopment
assetBaseUrl: '/build',
);

$vite = new Vite($configuration, entrypoints: ['resources/js/app.js']);
$vite = Vite::create($configuration, entrypoints: ['resources/js/app.js']);

$assets = $vite->resolve();

Expand Down Expand Up @@ -122,7 +122,7 @@ use PHPForge\Vite\Vite;
use Yiisoft\Aliases\Aliases;

static function (Aliases $aliases): Vite {
return new Vite(
return Vite::create(
new ProductionConfiguration(
manifestPath: $aliases->get('@public/build/.vite/manifest.json'),
assetBaseUrl: '/build',
Expand Down Expand Up @@ -167,7 +167,7 @@ $configuration = new DevelopmentConfiguration(
inlineModuleProviders: [new ReactRefreshPreamble()],
);

$vite = new Vite($configuration, entrypoints: ['resources/js/app.jsx']);
$vite = Vite::create($configuration, entrypoints: ['resources/js/app.jsx']);
```

Providers run in their configured order before `@vite/client` and the entrypoint scripts. The application owns the provider
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ library, which includes `ui-awesome/html-helper` transitively.
## Install the PHP package

```bash
composer require php-forge/vite:^0.1
composer require php-forge/vite:^0.2
```

## Configure the consuming project
Expand Down
9 changes: 7 additions & 2 deletions docs/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Unknown chunk fields are accepted as forward-compatible input and ignored. Known
Every `file`, `css`, and `assets` value must be a safe relative build path. Every static or dynamic reference must identify
another manifest entry.

Consumers constructing chunks directly can use `ManifestChunk::create($key, $file)` or its public two-argument constructor,
then replace optional fields with `withSrc()`, `withCss()`, `withAssets()`, `withEntry()`, `withName()`,
`withDynamicEntry()`, `withImports()`, and `withDynamicImports()`. Each modifier returns a new chunk. Optional values are
read through the corresponding typed getters.

## Initial-page resolution

For each requested entrypoint, the resolver:
Expand All @@ -39,8 +44,8 @@ prevents infinite recursion for malformed circular import graphs and prevents re
Selected entrypoint scripts are not also emitted as modulepreload assets.

`dynamicImports` are validated but are not placed in the initial page because the browser loads them when the application
executes the corresponding dynamic import. The `assets` field is represented in `ManifestChunk` for consumers inspecting a
manifest, but generic HTML tags cannot be inferred safely from those files and are not emitted automatically.
executes the corresponding dynamic import. The `assets` field is available through `ManifestChunk::assets()` for consumers
inspecting a manifest, but generic HTML tags cannot be inferred safely from those files and are not emitted automatically.

## Failure behavior

Expand Down
17 changes: 9 additions & 8 deletions docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ use PHPForge\Vite\Asset\AssetInterface;
use PHPForge\Vite\Asset\ModuleScript;
use PHPForge\Vite\Html\HtmlRenderOptions;

$options = new HtmlRenderOptions(
moduleScriptAttributes: ['crossorigin' => true],
stylesheetAttributes: ['media' => 'screen'],
attributeProvider: static fn(AssetInterface $asset): array => $asset instanceof ModuleScript
? ['data-entry' => 'application']
: [],
);
$options = HtmlRenderOptions::create()
->withModuleScriptAttributes(['crossorigin' => true])
->withStylesheetAttributes(['media' => 'screen'])
->withAttributeProvider(
static fn(AssetInterface $asset): array => $asset instanceof ModuleScript
? ['data-entry' => 'application']
: [],
);
```

Attribute names must begin with a letter or underscore and may otherwise contain letters, digits, underscores, or hyphens.
Expand All @@ -52,7 +53,7 @@ header("Content-Security-Policy: script-src 'nonce-{$nonce}' 'strict-dynamic'; o

$html = (new HtmlRenderer())->render(
$vite->resolve(),
new HtmlRenderOptions(nonce: $nonce),
HtmlRenderOptions::create()->withNonce($nonce),
);
```

Expand Down
4 changes: 2 additions & 2 deletions src/Asset/AssetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function all(): array
*
* @return AssetCollection A new collection holding both sequences.
*/
public function append(AssetInterface ...$assets): AssetCollection
public function append(AssetInterface ...$assets): self
{
return new self([...$this->assets, ...$assets]);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public function moduleScripts(): array
*
* @return AssetCollection A new collection holding both sequences.
*/
public function prepend(AssetInterface ...$assets): AssetCollection
public function prepend(AssetInterface ...$assets): self
{
return new self([...$assets, ...$this->assets]);
}
Expand Down
Loading
Loading