Skip to content

Commit b867421

Browse files
timacdonaldtaylorotwell
andauthoredMay 2, 2024··
Simplify asset story (#1438)
* Simplify assets story * Update Horizon.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 1b5a027 commit b867421

22 files changed

+265
-1554
lines changed
 

‎.gitattributes

-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
*.md diff=markdown
77
*.php diff=php
88

9-
public/*.css binary
10-
public/*.js binary
11-
129
/.github export-ignore
1310
/tests export-ignore
1411
.gitattributes export-ignore

‎.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/vendor
22
/laravel
33
/node_modules
4-
/public/app.js.LICENSE.txt
54
/phpunit.xml
65
composer.lock
76
.phpunit.result.cache

‎.styleci.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
php:
22
preset: laravel
3-
js: true
4-
css: true
3+
js:
4+
tab-width: 4
5+
use-tabs: false
6+
print-width: 120
7+
double-quotes: false
8+
trailing-commas: es5
9+
semicolons: true
10+
arrow-parens: always
11+
bracket-same-line: false
12+
bracket-spacing: true
13+
finder:
14+
exclude:
15+
- "dist"
16+
- "node_modules"
17+
- "vendor"
18+
name:
19+
- "*.js"
20+
- "*.jsx"
21+
css:
22+
tab-width: 4
23+
use-tabs: false
24+
print-width: 120
25+
double-quotes: false
26+
finder:
27+
exclude:
28+
- "dist"
29+
- "node_modules"
30+
- "vendor"
31+
name:
32+
- "*.css"
33+
- "*.scss"
34+
- "*.less"

‎public/build/app.css ‎dist/app.css

File renamed without changes.

‎public/build/app.js ‎dist/app.js

+25-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
File renamed without changes.

‎package-lock.json

+125-1,349
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
{
22
"name": "laravel-horizon",
33
"private": true,
4+
"type": "module",
45
"scripts": {
5-
"dev": "npm run development",
6-
"development": "NODE_ENV=development vite build --mode=development",
7-
"watch": "NODE_ENV=development vite build --mode=development --watch",
8-
"prod": "npm run production",
9-
"production": "NODE_ENV=production vite build"
6+
"build": "vite build",
7+
"watch": "vite build --watch"
108
},
119
"devDependencies": {
1210
"@vitejs/plugin-vue2": "^2.3.1",
1311
"axios": "^1.6.8",
1412
"bootstrap": "~5.1.3",
1513
"chart.js": "^2.9.4",
1614
"highlight.js": "^10.7.3",
17-
"laravel-vite-plugin": "^1.0.2",
1815
"md5": "^2.3.0",
1916
"moment": "^2.30.1",
2017
"moment-timezone": "^0.5.45",
2118
"phpunserialize": "^1.3.0",
22-
"resolve-url-loader": "^5.0.0",
2319
"sass": "^1.74.1",
2420
"sql-formatter": "^4.0.2",
2521
"vite": "^5.2.8",

‎public/build/favicon.png

-648 Bytes
Binary file not shown.

‎public/build/manifest.json

-25
This file was deleted.

‎resources/img/favicon.png

-648 Bytes
Binary file not shown.

‎resources/js/app.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from 'axios';
2-
import Vue from 'vue';
2+
import Vue from 'vue/dist/vue.esm.js';
33
import VueRouter from 'vue-router';
44
import VueJsonPretty from 'vue-json-pretty';
55
import 'vue-json-pretty/lib/styles.css';
@@ -8,8 +8,6 @@ import Routes from './routes';
88
import Alert from './components/Alert.vue';
99
import SchemeToggler from './components/SchemeToggler.vue';
1010

11-
import.meta.glob(['../img/**']);
12-
1311
let token = document.head.querySelector("meta[name='csrf-token']");
1412

1513
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

‎resources/js/components/SchemeToggler.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
},
3737
3838
calculateScheme () {
39-
const dark = document.querySelector('link[data-scheme="dark"]');
39+
const dark = document.querySelector('style[data-scheme="dark"]');
4040
4141
if (this.scheme == 'system') {
4242
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)');
4343
44-
dark.disabled = ! prefersDarkMode.matches;
44+
dark.media = prefersDarkMode.matches ? "" : "max-width: 1px";
4545
} else {
46-
dark.disabled = this.scheme != 'dark';
46+
dark.media = this.scheme == 'dark' ? "" : "max-width: 1px";
4747
}
4848
}
4949
}

‎resources/views/layout.blade.php

+3-28
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,19 @@
1-
@php
2-
$nonExistentFileName = public_path('/vendor/horizon/nonExistentFile');
3-
$previousHotFile = Vite::hotFile();
4-
5-
Vite::useHotFile($nonExistentFileName);
6-
@endphp
71
<!DOCTYPE html>
82
<html lang="en">
93
<head>
104
<!-- Meta Information -->
115
<meta charset="utf-8">
126
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
137
<meta name="csrf-token" content="{{ csrf_token() }}">
14-
<link rel="shortcut icon" href="{{ Vite::asset('resources/img/favicon.png', 'vendor/horizon') }}">
8+
<link rel="shortcut icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAipJREFUeNrEV8txwjAQtQ2HHCmB3JKbSQOYCoA0gD0pgFBBwpEToQAGKmDglpwgFdg5kZtNB1BBsuusZ4RY2ZZjYGd2jGWh97Q/rUwjpziPT3V4dECboDZoXZoSka5Al5vFNMqzrpkD2IFHn8B1ZAM6BCKbQgQAuAaPWQFgjoinsoipAEcTr0FrRjmyJxLLTAI5wXFXAehBGMPYcDKIIIm5kkAGOJpwAjqHRfYpbkOXvTBBypIwpT+HCvA3Cqi9Rta8EhHOHS1YCy1oWMKHmQIcGQ90wGMfLaZIoEGAoiDGOHmxhFTr5PGZJgncZYszEGC6ogX6nNn/Ay6RGDCfYveYVOFCJuAaumbPiIk1kyUNS2H6SZngyZrMWM+i/JVlXjK4QUVI3pRTpYPlaG6yeyGvm0Jef1ItiArwQBKu8G5bTMEIhKLkU3q65D+HgieE7+MCBHbygMVMOlCK+CnVDOUZ5s00ghCt2T45C+DDD2MBW/O066YFLYGvuXU5C9i6GYaLUzqr+olQtS5aIMwwtW6QfQnv7awNVanolEWgo9nABBb1cNeSmMDyigRWZkqdPrdEkDm3SRYMr7D7odwRXdIK8e7lOuAxh8W5pHtSiOhw8S4A7iX9IErlyC5b/7t+/7Ar4TKiEuyyRuJA5cQ5Wz8gEhgPNyXvfCQPVtgI+SPxAT/vSqiSEbXh70Uvp27GRSMNeJjV2Jp5V6MGpUeuUR0wAemKuwdy8ivAAJcc0R2NFxWtAAAAAElFTkSuQmCC">
159

1610
<title>Horizon{{ config('app.name') ? ' - ' . config('app.name') : '' }}</title>
1711

1812
<!-- Style sheets-->
1913
<link rel="preconnect" href="https://fonts.bunny.net">
2014
<link href="https://fonts.bunny.net/css?family=figtree:300,400,500,600" rel="stylesheet" />
21-
22-
<link rel="preload" as="style" href="{{ Vite::asset('resources/sass/styles.scss', 'vendor/horizon') }}" />
23-
<link rel="stylesheet" href="{{ Vite::asset('resources/sass/styles.scss', 'vendor/horizon') }}" data-scheme="light" />
24-
<link rel="preload" as="style" href="{{ Vite::asset('resources/sass/styles-dark.scss', 'vendor/horizon') }}" />
25-
<link rel="stylesheet" href="{{ Vite::asset('resources/sass/styles-dark.scss', 'vendor/horizon') }}" data-scheme="dark" />
15+
{{ Laravel\Horizon\Horizon::css() }}
16+
{{ Laravel\Horizon\Horizon::js() }}
2617
</head>
2718
<body>
2819
<div id="horizon" v-cloak>
@@ -127,12 +118,6 @@
127118
</div>
128119

129120
<div class="col-10">
130-
@if (! $assetsAreCurrent)
131-
<div class="alert alert-warning">
132-
The published Horizon assets are not up-to-date with the installed version. To update, run:<br/><code>php artisan horizon:publish</code>
133-
</div>
134-
@endif
135-
136121
@if ($isDownForMaintenance)
137122
<div class="alert alert-warning">
138123
This application is in "maintenance mode". Queued jobs may not be processed unless your worker is using the "force" flag.
@@ -144,15 +129,5 @@
144129
</div>
145130
</div>
146131
</div>
147-
148-
<!-- Global Horizon Object -->
149-
<script>
150-
window.Horizon = @json($horizonScriptVariables);
151-
</script>
152-
153-
@vite('resources/js/app.js', 'vendor/horizon')
154132
</body>
155133
</html>
156-
@php
157-
Vite::useHotFile($previousHotFile);
158-
@endphp

‎src/Console/PublishCommand.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ class PublishCommand extends Command
2929
*/
3030
public function handle()
3131
{
32-
$this->call('vendor:publish', [
33-
'--tag' => 'horizon-assets',
34-
'--force' => true,
35-
]);
32+
$this->components->warn('Horizon no longer publishes its assets. You may stop calling the `horizon:publish` command.');
3633
}
3734
}

‎src/Horizon.php

+50-19
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
use Closure;
66
use Exception;
7-
use Illuminate\Support\Facades\File;
7+
use Illuminate\Contracts\Support\Htmlable;
8+
use Illuminate\Support\HtmlString;
9+
use Illuminate\Support\Js;
810
use RuntimeException;
911

1012
class Horizon
@@ -110,6 +112,53 @@ public static function use($connection)
110112
config(['database.redis.horizon' => $config]);
111113
}
112114

115+
/**
116+
* Get the CSS for the Horizon dashboard.
117+
*
118+
* @return Illuminate\Contracts\Support\Htmlable
119+
*/
120+
public static function css()
121+
{
122+
if (($light = @file_get_contents(__DIR__.'/../dist/styles.css')) === false) {
123+
throw new RuntimeException('Unable to load the Horizon dashboard light CSS.');
124+
}
125+
126+
if (($dark = @file_get_contents(__DIR__.'/../dist/styles-dark.css')) === false) {
127+
throw new RuntimeException('Unable to load the Horizon dashboard dark CSS.');
128+
}
129+
130+
if (($app = @file_get_contents(__DIR__.'/../dist/app.css')) === false) {
131+
throw new RuntimeException('Unable to load the Horizon dashboard CSS.');
132+
}
133+
134+
return new HtmlString(<<<HTML
135+
<style data-scheme="light">{$light}</style>
136+
<style data-scheme="dark">{$dark}</style>
137+
<style>{$app}</style>
138+
HTML);
139+
}
140+
141+
/**
142+
* Get the JS for the Horizon dashboard.
143+
*
144+
* @return \Illuminate\Contracts\Support\Htmlable
145+
*/
146+
public static function js()
147+
{
148+
if (($js = @file_get_contents(__DIR__.'/../dist/app.js')) === false) {
149+
throw new RuntimeException('Unable to load the Horizon dashboard JavaScript.');
150+
}
151+
152+
$horizon = Js::from(static::scriptVariables());
153+
154+
return new HtmlString(<<<HTML
155+
<script type="module">
156+
window.Horizon = {$horizon};
157+
{$js}
158+
</script>
159+
HTML);
160+
}
161+
113162
/**
114163
* Specifies that Horizon should use the dark theme.
115164
*
@@ -176,22 +225,4 @@ public static function routeSmsNotificationsTo($number)
176225

177226
return new static;
178227
}
179-
180-
/**
181-
* Determine if Horizon's published assets are up-to-date.
182-
*
183-
* @return bool
184-
*
185-
* @throws \RuntimeException
186-
*/
187-
public static function assetsAreCurrent()
188-
{
189-
$publishedPath = public_path('vendor/horizon/manifest.json');
190-
191-
if (! File::exists($publishedPath)) {
192-
throw new RuntimeException('Horizon assets are not published. Please run: php artisan horizon:publish');
193-
}
194-
195-
return File::get($publishedPath) === File::get(__DIR__.'/../public/build/manifest.json');
196-
}
197228
}

‎src/HorizonServiceProvider.php

-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public function boot()
2323
$this->registerEvents();
2424
$this->registerRoutes();
2525
$this->registerResources();
26-
$this->defineAssetPublishing();
2726
$this->offerPublishing();
2827
$this->registerCommands();
2928
}
@@ -75,18 +74,6 @@ protected function registerResources()
7574
$this->loadViewsFrom(__DIR__.'/../resources/views', 'horizon');
7675
}
7776

78-
/**
79-
* Define the asset publishing configuration.
80-
*
81-
* @return void
82-
*/
83-
public function defineAssetPublishing()
84-
{
85-
$this->publishes([
86-
HORIZON_PATH.'/public/build' => public_path('vendor/horizon'),
87-
], ['horizon-assets', 'laravel-assets']);
88-
}
89-
9077
/**
9178
* Setup the resource publishing groups for Horizon.
9279
*

‎src/Http/Controllers/HomeController.php

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Laravel\Horizon\Http\Controllers;
44

55
use Illuminate\Support\Facades\App;
6-
use Laravel\Horizon\Horizon;
76

87
class HomeController extends Controller
98
{
@@ -15,8 +14,6 @@ class HomeController extends Controller
1514
public function index()
1615
{
1716
return view('horizon::layout', [
18-
'assetsAreCurrent' => Horizon::assetsAreCurrent(),
19-
'horizonScriptVariables' => Horizon::scriptVariables(),
2017
'isDownForMaintenance' => App::isDownForMaintenance(),
2118
]);
2219
}

‎testbench.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,3 @@ workbench:
2020
- db-wipe
2121
- migrate-fresh
2222
assets: []
23-
sync:
24-
- from: ./public
25-
to: public/vendor/horizon

‎vite.config.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import vue2 from '@vitejs/plugin-vue2';
2+
3+
/** @type {import('vite').UserConfig} */
4+
export default {
5+
plugins: [vue2()],
6+
build: {
7+
assetsDir: '',
8+
rollupOptions: {
9+
input: ['resources/js/app.js', 'resources/sass/styles.scss', 'resources/sass/styles-dark.scss'],
10+
output: {
11+
entryFileNames: '[name].js',
12+
chunkFileNames: '[name].js',
13+
assetFileNames: '[name].[ext]',
14+
},
15+
},
16+
},
17+
resolve: {
18+
alias: {
19+
'@': '/resources/js',
20+
},
21+
},
22+
};

‎vite.config.mjs

-66
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.