Download the PHP package wp-strap/vite without Composer
On this page you can find all versions of the php package wp-strap/vite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wp-strap/vite
More information about wp-strap/vite
Files in wp-strap/vite
Package vite
Short Description A collection of back-end utilities for WordPress development with ViteJS.
License BSD-2-Clause
Informations about the package vite
Vite PHP
A library of back-end/PHP utilities for WordPress development with ViteJS. You can read more about ViteJS on [vitejs.dev](https://vitejs.dev)
Usages
Install dependency into your project.
This exposes some classes which are responsible for generating asset URLs from Vite's manifest.json that you can register or enqueue. It's also responsible for enabling HMR when the ViteJS dev server is running.
This package is made for:
But can be used with any ViteJS setups.
The classes follow PSR practices with interfaces, so it can be included trough OOP with dependency injection and IoC containers. It also provides a Facade class that allows you to use static methods instead to call the methods everywhere you like.
Example with using the facade:
Example with using instances
Example with using instances wih functions
Example with using the League Container
DevServer
Assets::devServer()->start(3000');
OR (new DevServer($assets))->start('3000');
The dev server class is responsible for listening to the ViteJS dev server using CURL, checking if it's running locally on port 3000 which you can adjust using the optional param from the start() method as seen above.
If it can validate the dev server is running, it will inject viteJS scripts provided from the dev server, filter all asset urls and load source files instead (from the assets::get(), assets:css(), assets::js() etc. methods), and alter the script tags to make sure the source files can be loaded as modules for HMR.
This should only be run on local/dev environments. As it's using CURL on each request, so you don't want to run this on production.
Project Example
You can find more info and a project example here: https://github.com/wp-strap/wp-vite-starter