mimmi20 / laminasviewrenderer-vite-url
Provides a Viewhelper to render urls for resources build with Vite
Installs: 148 736
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
- laminas/laminas-view: ^2.39.0
- psr/container: ^1.1.2
Requires (Dev)
- ext-ctype: *
- ext-dom: *
- ext-simplexml: *
- ext-tokenizer: *
- ext-xml: *
- ext-xmlwriter: *
- infection/infection: ^0.30.3
- laminas/laminas-modulemanager: ^2.17.0
- laminas/laminas-servicemanager: ^3.22.1
- mikey179/vfsstream: ^1.6.12
- mimmi20/coding-standard: ^6.1.7
- nikic/php-parser: ^5.6.0
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.1.21
- phpstan/phpstan-deprecation-rules: ^2.0.3
- phpunit/phpunit: ^12.3.0
- rector/rector: ^2.1.2
- rector/type-perfect: ^2.1.0
- shipmonk/composer-dependency-analyser: ^1.8.3
- symfony/process: ^7.3.0
- symplify/phpstan-rules: ^14.6.11
- tomasvotruba/cognitive-complexity: ^1.0.0
- tomasvotruba/type-coverage: ^2.0.2
- tomasvotruba/unused-public: ^2.0.1
Suggests
- laminas/laminas-modulemanager: to register this project as module
- laminas/laminas-servicemanager: to use the viewhelper factories
This package is auto-updated.
Last update: 2025-08-02 11:01:26 UTC
README
Code Status
Introduction
This component provides a view helper to render urls for resources build with Vite
Requirements
This library requires PHP 8.3+.
Installation
Run
composer require mimmi20/laminasviewrenderer-vite-url
Prepare Vite
In your Vite config, you need to activate the manifest.
publicDir: 'public', base: '/dist/', build: { // ... outDir: 'public/dist', // relative to the `root` folder manifest: true, // ... rollupOptions: { input: [ path.resolve(__dirname, 'public/css/styles.css'), path.resolve(__dirname, 'public/scss/styles.scss'), ] } }
The required manifest file and the resorce files are created when running Vite's build command.
npx vite build
Config
This viewhelper needs a config to know where the public and the build directories are. The directories have to match the directories configured for Vite.
<?php return [ // ... 'vite-url' => [ 'public-dir' => 'public', // <-- relative to the project root 'build-dir' => 'dist', // <-- relative to the public directory ], // ... ];
Usage
Now you may add a file build with Vite. It is nessesary to use the exact path, you use in the Vite config. Otherwise the file can not be found in the manifest.
$this->headLink()->appendStylesheet($this->viteUrl()->file('public/css/styles.css'), 'screen', ['rel' => 'stylesheet']); $this->headLink()->appendStylesheet($this->viteUrl()->file('public/scss/styles.scss'), 'screen', ['rel' => 'stylesheet']);
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.