Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e15aca0
🚧 Tailwind v4
retlehs Jan 20, 2025
cdb9130
Update theme.json generator
retlehs Jan 20, 2025
f8a76ad
✨ Enqueue assets
retlehs Jan 20, 2025
b29369e
unused
retlehs Jan 20, 2025
aca0600
Revert "✨ Enqueue assets"
retlehs Jan 20, 2025
df5a4a8
used
retlehs Jan 20, 2025
e4c1c50
inject editor css
retlehs Jan 20, 2025
47fdba0
Merge branch 'main' into tailwind-v4
retlehs Jan 20, 2025
b4fd710
⬆️ Tailwind v4
retlehs Jan 25, 2025
e617134
Fix theme.json generation with custom styles
retlehs Jan 25, 2025
221d074
Improve dev server integration with editor
retlehs Jan 25, 2025
415f5bc
formatting
retlehs Jan 25, 2025
a6046db
🚧 Improve dev server integration with editor
retlehs Jan 26, 2025
34a381f
🔎
retlehs Jan 26, 2025
32b3ae4
better
retlehs Jan 26, 2025
b18072b
Fix custom colors theme.json generation
retlehs Jan 27, 2025
f5d593d
CSS HMR
retlehs Jan 28, 2025
8cdce89
🧑‍💻 Utilize the `Vite` facade where possible
Log1x Jan 28, 2025
9840dc3
🧑‍💻 Add the `editor.deps.json` file to the manifest
Log1x Jan 28, 2025
51543d2
📌 Temporarily pin Acorn to `dev-main`
Log1x Jan 28, 2025
f839400
🎨 Improve docblock wording
Log1x Jan 28, 2025
6b1504e
🎨 Use the `@vite` directive instead of `wp_head`
Log1x Jan 28, 2025
b46b439
🎨 Keep things uniform for now
Log1x Jan 28, 2025
71b8826
🎨 Improve regex for custom property matching (#3213)
csorrentino Jan 28, 2025
c0eb48e
🩹 Fix theme.json generation to handle :host selector in theme layer o…
stuart-james Feb 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 50 additions & 24 deletions app/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,85 @@

use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\Str;

/**
* Inject the Vite assets into the head.
* Inject styles into the block editor.
*
* @return void
* @return array
*/
add_filter('wp_head', function () {
echo Str::wrap(app('assets.vite')([
'resources/css/app.css',
'resources/js/app.js',
]), "\n");
add_filter('block_editor_settings_all', function ($settings) {
$style = Vite::asset('resources/css/editor.css');

$settings['styles'][] = [
'css' => Vite::isRunningHot()
? "@import url('{$style}')"
: Vite::content('resources/css/editor.css'),
];

return $settings;
});

/**
* Inject assets into the block editor.
* Inject scripts into the block editor.
*
* @return void
*/
add_filter('admin_head', function () {
$screen = get_current_screen();

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

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

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

echo Str::wrap(app('assets.vite')([
'resources/css/editor.css',
echo Vite::withEntryPoints([
'resources/js/editor.js',
]), "\n");
])->toHtml();
});

/**
* Use theme.json from the build directory
* Add Vite's HMR client to the block editor.
*
* @param string $path
* @param string $file
* @return string
* @return void
*/
add_filter('theme_file_path', function (string $path, string $file): string {
if ($file === 'theme.json') {
return public_path().'/build/assets/theme.json';
add_action('enqueue_block_assets', function () {
if (! is_admin() || ! get_current_screen()?->is_block_editor()) {
return;
}

return $path;
if (! Vite::isRunningHot()) {
return;
}

$script = sprintf(
<<<'JS'
window.__vite_client_url = '%s';

window.self !== window.top && document.head.appendChild(
Object.assign(document.createElement('script'), { type: 'module', src: '%s' })
);
JS,
untrailingslashit(Vite::asset('')),
Vite::asset('@vite/client')
);

wp_add_inline_script('wp-blocks', $script);
});

/**
* Use the generated theme.json file.
*
* @return string
*/
add_filter('theme_file_path', function ($path, $file) {
return $file === 'theme.json'
? public_path('build/assets/theme.json')
: $path;
}, 10, 2);

/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"require": {
"php": ">=8.2",
"roots/acorn": "v5.0.0-beta.2"
"roots/acorn": "dev-main"
},
"require-dev": {
"laravel/pint": "^1.13"
Expand Down
Loading