Skip to content

Commit

Permalink
🚧 Use Vite for build
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Nifong <[email protected]>
  • Loading branch information
retlehs and Log1x committed Dec 8, 2024
1 parent b81a59e commit f9de13a
Show file tree
Hide file tree
Showing 15 changed files with 3,886 additions and 7,808 deletions.
55 changes: 46 additions & 9 deletions app/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,62 @@

namespace App;

use function Roots\bundle;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\Str;

/**
* Register the theme assets.
* Inject the Vite assets into the head.
*
* @return void
*/
add_action('wp_enqueue_scripts', function () {
bundle('app')->enqueue();
}, 100);
add_filter('wp_head', function () {
echo Str::wrap(app('assets.vite')([
'resources/styles/app.css',
'resources/scripts/app.js',
]), "\n");
});

/**
* Register the theme assets with the block editor.
* Inject assets into the block editor.
*
* @return void
*/
add_action('enqueue_block_editor_assets', function () {
bundle('editor')->enqueue();
}, 100);
add_filter('admin_head', function () {
$screen = get_current_screen();

if (! $screen?->is_block_editor()) {
return;
}

$dependencies = File::json(public_path('build/editor.deps.json')) ?? [];

foreach ($dependencies as $dependency) {
if (! wp_script_is($dependency)) {
wp_enqueue_script($dependency);
}
}

echo Str::wrap(app('assets.vite')([
'resources/styles/editor.css',
'resources/scripts/editor.js',
]), "\n");
});

/**
* Use theme.json from the build directory
*
* @param string $path
* @param string $file
* @return string
*/
add_filter('theme_file_path', function (string $path, string $file): string {
if ($file === 'theme.json') {
return public_path() . '/build/theme.json';
}

return $path;
}, 10, 2);

/**
* Register the initial theme setup.
Expand Down
80 changes: 0 additions & 80 deletions bud.config.js

This file was deleted.

40 changes: 40 additions & 0 deletions config/assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Default Assets Manifest
|--------------------------------------------------------------------------
|
| Here you may specify the default asset manifest that should be used.
| The "theme" manifest is recommended as the default as it cedes ultimate
| authority of your application's assets to the theme.
|
*/

'default' => 'theme',

/*
|--------------------------------------------------------------------------
| Assets Manifests
|--------------------------------------------------------------------------
|
| Manifests contain lists of assets that are referenced by static keys that
| point to dynamic locations, such as a cache-busted location. We currently
| support two types of manifest:
|
| assets: key-value pairs to match assets to their revved counterparts
|
| bundles: a series of entrypoints for loading bundles
|
*/

'manifests' => [
'theme' => [
'path' => get_theme_file_path('public'),
'url' => get_theme_file_uri('public'),
'bundles' => get_theme_file_path('public/build/manifest.json'),
],
],
];
34 changes: 0 additions & 34 deletions jsconfig.json

This file was deleted.

Loading

0 comments on commit f9de13a

Please sign in to comment.