Skip to content

feat(vite): add namespace support for multi-build setups#41

Merged
josbeir merged 3 commits intomainfrom
feat/vite-namespaces
Mar 11, 2026
Merged

feat(vite): add namespace support for multi-build setups#41
josbeir merged 3 commits intomainfrom
feat/vite-namespaces

Conversation

@josbeir
Copy link
Copy Markdown
Owner

@josbeir josbeir commented Mar 11, 2026

Adds namespace support to ViteExtension, allowing multiple independent Vite builds (e.g. a plugin or theme) to coexist in a single Sugar application.

What changed

New: ViteConfig value object

A new ViteConfig readonly class consolidates all per-build configuration: assetBaseUrl, manifestPath, devServerUrl, injectClient, and defaultEntry. It is used both for the default (root) context and for named namespaces, keeping resolver internals DRY.

ViteExtension — new $namespaces parameter

new ViteExtension(
    assetBaseUrl: '/build/',
    manifestPath: ROOT . '/webroot/build/.vite/manifest.json',
    namespaces: [
        'theme' => new ViteConfig(
            assetBaseUrl: '/theme/build/',
            manifestPath: ROOT . '/plugins/Theme/webroot/build/.vite/manifest.json',
            devServerUrl: 'http://localhost:5174',
        ),
    ],
)

Template syntax

Namespace entries use an @name/ prefix, consistent with Sugar's existing template namespace convention:

<s-template s:vite="'@theme/resources/js/theme.ts'" />

<!-- Mix default and namespaced entries -->
<s-template s:vite="['resources/js/app.ts', '@theme/resources/js/theme.ts']" />

ViteAssetResolver — fully namespace-aware

  • Per-namespace manifest caching (array<string, array> keyed by namespace)
  • Per-namespace @vite/client injection tracking
  • devServerUrl falls back to the root config when omitted from a namespace ViteConfig
  • Unknown namespace throws a descriptive exception listing all registered namespaces

Tests

  • 9 new unit tests in ViteAssetResolverTest covering: dev server routing per namespace, root server fallback, independent manifest loading, unknown namespace error, per-namespace client injection, entry deduplication, and defaultEntry usage
  • 1 new unit test in ViteExtensionTest verifying namespace configs flow through to the resolver
  • 2 unit tests in new ViteConfigTest for the value object
  • 6 new integration tests in ViteIntegrationTest covering multi-build dev/prod rendering and mixed-namespace entry lists

Backward compatibility

Fully backward-compatible. The $namespaces parameter defaults to [] and all existing flat constructor parameters on ViteExtension are unchanged.

Copilot AI review requested due to automatic review settings March 11, 2026 17:16
@josbeir josbeir force-pushed the feat/vite-namespaces branch from 799a34c to 9be59e9 Compare March 11, 2026 17:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds namespaced Vite build support to Sugar’s Vite integration so multiple independent Vite builds (e.g., app + theme/plugin) can coexist and be referenced from templates via an @name/ prefix.

Changes:

  • Introduces ViteConfig as a per-build configuration value object and threads it through ViteExtensionViteAssetResolver.
  • Makes ViteAssetResolver namespace-aware (per-namespace manifest caching, dev server URL routing, and @vite/client injection tracking).
  • Adds/updates unit + integration tests and extends Vite docs with namespace usage.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/Extension/Vite/ViteExtension.php Accepts namespace configs and constructs the resolver using a default ViteConfig plus named namespace configs.
src/Extension/Vite/ViteConfig.php Adds a readonly value object encapsulating per-build Vite settings.
src/Extension/Vite/Runtime/ViteAssetResolver.php Implements namespaced entry parsing, per-namespace manifest caching, and per-namespace dev server/client injection behavior.
tests/Unit/Extension/Vite/ViteExtensionTest.php Verifies namespace configs flow through the extension into the resolver.
tests/Unit/Extension/Vite/ViteConfigTest.php Covers ViteConfig construction and default values.
tests/Unit/Extension/Vite/Runtime/ViteAssetResolverTest.php Adds namespace-specific resolver behavior tests and refactors test setup via a helper.
tests/Integration/ViteIntegrationTest.php Exercises namespaced dev/prod rendering through the full engine pipeline.
docs/content/extensions/vite.dj Documents the new namespace configuration and template syntax.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@josbeir josbeir merged commit afa41b0 into main Mar 11, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants