Skip to content

Commit a482791

Browse files
retlehsLog1x
andauthored
🔧 Use Vite for build (#3199)
Co-authored-by: Brandon Nifong <[email protected]>
1 parent bc60adb commit a482791

File tree

19 files changed

+3749
-7787
lines changed

19 files changed

+3749
-7787
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ jobs:
2525
uses: actions/setup-node@v4
2626
with:
2727
node-version: ${{ matrix.node }}
28-
cache: 'yarn'
28+
cache: 'npm'
2929
env:
3030
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3131

32-
- name: Install dependencies using Yarn
33-
run: yarn install --frozen-lockfile
32+
- name: Install dependencies using npm
33+
run: npm ci
3434

3535
- name: Build and compile assets
3636
run: |
37-
yarn build
38-
cat public/entrypoints.json
39-
cat public/manifest.json
37+
npm run build
38+
cat public/build/manifest.json
4039
4140
php:
4241
name: PHP ${{ matrix.php }}

app/setup.php

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,62 @@
66

77
namespace App;
88

9-
use function Roots\bundle;
9+
use Illuminate\Support\Facades\File;
10+
use Illuminate\Support\Facades\Vite;
11+
use Illuminate\Support\Str;
1012

1113
/**
12-
* Register the theme assets.
14+
* Inject the Vite assets into the head.
1315
*
1416
* @return void
1517
*/
16-
add_action('wp_enqueue_scripts', function () {
17-
bundle('app')->enqueue();
18-
}, 100);
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");
23+
});
1924

2025
/**
21-
* Register the theme assets with the block editor.
26+
* Inject assets into the block editor.
2227
*
2328
* @return void
2429
*/
25-
add_action('enqueue_block_editor_assets', function () {
26-
bundle('editor')->enqueue();
27-
}, 100);
30+
add_filter('admin_head', function () {
31+
$screen = get_current_screen();
32+
33+
if (! $screen?->is_block_editor()) {
34+
return;
35+
}
36+
37+
$dependencies = File::json(public_path('build/editor.deps.json')) ?? [];
38+
39+
foreach ($dependencies as $dependency) {
40+
if (! wp_script_is($dependency)) {
41+
wp_enqueue_script($dependency);
42+
}
43+
}
44+
45+
echo Str::wrap(app('assets.vite')([
46+
'resources/css/editor.css',
47+
'resources/js/editor.js',
48+
]), "\n");
49+
});
50+
51+
/**
52+
* Use theme.json from the build directory
53+
*
54+
* @param string $path
55+
* @param string $file
56+
* @return string
57+
*/
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';
61+
}
62+
63+
return $path;
64+
}, 10, 2);
2865

2966
/**
3067
* Register the initial theme setup.

bud.config.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

config/assets.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Default Assets Manifest
8+
|--------------------------------------------------------------------------
9+
|
10+
| Here you may specify the default asset manifest that should be used.
11+
| The "theme" manifest is recommended as the default as it cedes ultimate
12+
| authority of your application's assets to the theme.
13+
|
14+
*/
15+
16+
'default' => 'theme',
17+
18+
/*
19+
|--------------------------------------------------------------------------
20+
| Assets Manifests
21+
|--------------------------------------------------------------------------
22+
|
23+
| Manifests contain lists of assets that are referenced by static keys that
24+
| point to dynamic locations, such as a cache-busted location. We currently
25+
| support two types of manifest:
26+
|
27+
| assets: key-value pairs to match assets to their revved counterparts
28+
|
29+
| bundles: a series of entrypoints for loading bundles
30+
|
31+
*/
32+
33+
'manifests' => [
34+
'theme' => [
35+
'path' => get_theme_file_path('public'),
36+
'url' => get_theme_file_uri('public'),
37+
'bundles' => get_theme_file_path('public/build/manifest.json'),
38+
],
39+
],
40+
];

jsconfig.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)