kresnasatya / wp-vite-theme
Generic WordPress theme integrate with ViteJS
Installs: 45
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 1
Forks: 1
Type:project
pkg:composer/kresnasatya/wp-vite-theme
Requires
- php: ^8.1
- vlucas/phpdotenv: ^5.5
README
Proof of Concept (PoC) WordPress theme integrate with ViteJS. Motivated from wp-theme-vite-tailwind.
Requirements
- PHP version >= 8.2
- NodeJS version >= 18
Brief Setup for Development Mode
- You have WordPress project that run with
wp serveror any other development tools like Laragon or Valet. It will shows URL likehttp://localhost:8080if you usewp serveroryour-wp-project.testif you use Laragon or Valet. - Go to
wp-content/themesdirectory. Then downloadwp-vite-themeproject with command below.
composer create-project kresnasatya/wp-vite-theme <your-theme-name> && cd <your-theme-name>
- Run
composer install. - Run
pnpm installornpm install. - Run
pnpm run devornpm run dev. - Change
VITE_SERVERvalue in.envfile with the Vite URL.
If you open the Vite URL it will contain empty file because it serves as a runner for your assets such as CSS and JavaScript.
Try to edit index.php or any file with .php extension then save it! Vite will trigger full-reload event so browser reload the page automatically. Thanks to handleHotUpdate hook from Vite.
How to handling static assets in CSS and JS in WordPress + Vite Environment?
In production mode, static assets like images, fonts work well BUT not in development mode!
In order to make it works, you need to set a symbolic link or symlink from source folder to destination folder. Here's the example.
# I store my images file in public directory on wp-vite-theme. # I make a WordPress project called wpground. # I make a WordPress theme called wp-vite-theme. # The ~ is a tilde symbol mean a "home" symbol in macOS. # Images ln -s ~/wpground/wp-content/wp-vite-theme/public/images ~/wpground/images # Fonts ln -s ~/wpground/wp-content/wp-vite-theme/public/fonts ~/wpground/fonts
Brief Setup for Production Mode
- Stop
wp serverandpnpm run devornpm run dev. - Change the value of
VITE_ENVin.envfile fromdevelopmenttoproduction. - Run command
pnpm run buildornpm run build. - Run
wp serveragain.
Credits
- Photo by Tom Delanoue on Unsplash
- Photo by mono-log on Unsplash