akki-io / laravel-nova-assets
A simple package for laravel nova to manage all nova related assets.
Requires
- php: ^7.3|^8.0
- symfony/process: ^5.4|^6.0
This package is auto-updated.
Last update: 2024-10-28 07:53:13 UTC
README
Laravel Nova Search
This package provides a console command to convert dynamic JS/CSS to static JS/CSS assets.
Requirements
- laravel-mix v6.0+
- php 7.3+
- laravel nova 3.0+
Installation
You can install the package via composer:
composer require akki-io/laravel-nova-assets
Publish the package files:
php artisan vendor:publish --provider 'AkkiIo\LaravelNovaAssets\LaravelNovaAssetsServiceProvider'
This will publish the
- config file
config/laravel-nova-assets.php
and - the webpack file
webpack.mix.nova.js
.
Usage
To create static assets the package provides a simple console command that will do the job for you.
Run
php artisan nova:mix
Once the command is executed you will need to update the laravel nova auth layout auth->layout.blade.php
and main layout layout.blade.php
to use the compiled assets.
- Copy the auth layout
vendor/laravel/nova/resources/views/auth/layout.blade.php
toresources/views/vendor/nova/auth/layout.blade.php
- Copy the main layout
vendor/laravel/nova/resources/views/layout.blade.php
toresources/views/vendor/nova/layout.blade.php
Add manifest files above the </head>
tag for both files.
<link rel="manifest" href="/vendor/laravel-nova-assets/mix-manifest.json">
Replace these following section in the newly copied files.
Original Content
// Tool Styles @foreach(\Laravel\Nova\Nova::availableStyles(.... .... @endforeach
New Content
<link rel="stylesheet" href="{{ mix('tool-styles.css', 'vendor/laravel-nova-assets') }}">
Original Content
<!-- Theme Styles --> @foreach(\Laravel\Nova\Nova::themeStyles() ...) .... @endforeach
New Content
<link rel="stylesheet" href="{{ mix('theme-styles.css', 'vendor/laravel-nova-assets') }}">
Original Content
<!-- Tool Scripts --> @foreach (\Laravel\Nova\Nova::availableScripts(request()) ...) ..... @endforeach
New Content
<script src="{{ mix('tool-scripts.js', 'vendor/laravel-nova-assets') }}"></script>
If you are using custom scripts and styles, add the following sections to these files accordingly.
<link rel="stylesheet" href="{{ mix('custom-styles.css', 'vendor/laravel-nova-assets') }}">
<script src="{{ mix('custom-scripts.js', 'vendor/laravel-nova-assets') }}"></script>
For copyright reason I cannot include those files in this project.
Adding custom CSS and JSS
You can specify you custom CSS/JS in the config file laravel-nova-assets.php
under the styles
and scripts
section.
Running the command on a CI/CD
You will need to create a dummy user if you are using this command to generate assets. Unfortunately, I was not able to find a work around for this.
Using CDN
There are few packages that already provides this feature, some of these are
arubacao/asset-cdn
- https://github.com/arubacao/asset-cdnpubliux/laravelcdn
- https://github.com/publiux/laravelcdn
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email hello@akki.io instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.