Skip to content

Commit 723506d

Browse files
retlehsLog1xcsorrentinostuart-james
authored
✨ Tailwind v4 (#3208)
Co-authored-by: Brandon <[email protected]> Co-authored-by: csorrentino <[email protected]> Co-authored-by: stuart <[email protected]>
1 parent 8d5a1ac commit 723506d

File tree

12 files changed

+752
-1509
lines changed

12 files changed

+752
-1509
lines changed

app/setup.php

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,85 @@
88

99
use Illuminate\Support\Facades\File;
1010
use Illuminate\Support\Facades\Vite;
11-
use Illuminate\Support\Str;
1211

1312
/**
14-
* Inject the Vite assets into the head.
13+
* Inject styles into the block editor.
1514
*
16-
* @return void
15+
* @return array
1716
*/
18-
add_filter('wp_head', function () {
19-
echo Str::wrap(app('assets.vite')([
20-
'resources/css/app.css',
21-
'resources/js/app.js',
22-
]), "\n");
17+
add_filter('block_editor_settings_all', function ($settings) {
18+
$style = Vite::asset('resources/css/editor.css');
19+
20+
$settings['styles'][] = [
21+
'css' => Vite::isRunningHot()
22+
? "@import url('{$style}')"
23+
: Vite::content('resources/css/editor.css'),
24+
];
25+
26+
return $settings;
2327
});
2428

2529
/**
26-
* Inject assets into the block editor.
30+
* Inject scripts into the block editor.
2731
*
2832
* @return void
2933
*/
3034
add_filter('admin_head', function () {
31-
$screen = get_current_screen();
32-
33-
if (! $screen?->is_block_editor()) {
35+
if (! get_current_screen()?->is_block_editor()) {
3436
return;
3537
}
3638

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

3941
foreach ($dependencies as $dependency) {
4042
if (! wp_script_is($dependency)) {
4143
wp_enqueue_script($dependency);
4244
}
4345
}
4446

45-
echo Str::wrap(app('assets.vite')([
46-
'resources/css/editor.css',
47+
echo Vite::withEntryPoints([
4748
'resources/js/editor.js',
48-
]), "\n");
49+
])->toHtml();
4950
});
5051

5152
/**
52-
* Use theme.json from the build directory
53+
* Add Vite's HMR client to the block editor.
5354
*
54-
* @param string $path
55-
* @param string $file
56-
* @return string
55+
* @return void
5756
*/
58-
add_filter('theme_file_path', function (string $path, string $file): string {
59-
if ($file === 'theme.json') {
60-
return public_path().'/build/assets/theme.json';
57+
add_action('enqueue_block_assets', function () {
58+
if (! is_admin() || ! get_current_screen()?->is_block_editor()) {
59+
return;
6160
}
6261

63-
return $path;
62+
if (! Vite::isRunningHot()) {
63+
return;
64+
}
65+
66+
$script = sprintf(
67+
<<<'JS'
68+
window.__vite_client_url = '%s';
69+
70+
window.self !== window.top && document.head.appendChild(
71+
Object.assign(document.createElement('script'), { type: 'module', src: '%s' })
72+
);
73+
JS,
74+
untrailingslashit(Vite::asset('')),
75+
Vite::asset('@vite/client')
76+
);
77+
78+
wp_add_inline_script('wp-blocks', $script);
79+
});
80+
81+
/**
82+
* Use the generated theme.json file.
83+
*
84+
* @return string
85+
*/
86+
add_filter('theme_file_path', function ($path, $file) {
87+
return $file === 'theme.json'
88+
? public_path('build/assets/theme.json')
89+
: $path;
6490
}, 10, 2);
6591

6692
/**

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
},
4141
"require": {
4242
"php": ">=8.2",
43-
"roots/acorn": "v5.0.0-beta.2"
43+
"roots/acorn": "dev-main"
4444
},
4545
"require-dev": {
4646
"laravel/pint": "^1.13"

0 commit comments

Comments
 (0)