laravel / nova-issues

556 stars 34 forks source link

Custom stylesheets and custom JavaScript do not work with Laravel Vapor #2822

Closed JoshOldenburg closed 4 years ago

JoshOldenburg commented 4 years ago

Description:

Custom scripts included with Nova::script() or custom stylesheets included with Nova::style() cannot be included when running on Laravel Vapor. On Vapor the assets are only held on Cloudfront so they can't be directly passed to the client by ScriptController (https://github.com/laravel/nova/blob/3.0/src/Http/Controllers/ScriptController.php).

The Nova::remoteScript() method also doesn't work when using asset() as the argument as ScriptController runs filemtime on a URL in that case, which fails. (remoteScript() is functionally not different from script() in this case and I just used style() as there is no remoteStyle() method.)

Detailed steps to reproduce the issue on a fresh Nova installation:

Set up a Laravel Vapor environment. Then add the following to the NovaServiceProvider, where the script and style paths are updated to be any JS/CSS file in the public directory.

public function boot(): void
{
    parent::boot();
    Nova::serving(static function (ServingNova $event): void {
        Nova::remoteScript(asset('js/nova.js'));
        Nova::style('custom-style', asset('css/nova.css'));
    });
}

It also does not work without the wrapping asset() call, for instance, Nova::script('custom-script', __DIR__.'/../../public/js/nova.js').

taylorotwell commented 4 years ago

What happens when you use remoteScript in this way?

For the style call, can you just move the CSS out of the public directory and put it somewhere else... Typically this kind of thing would be in a package?

JoshOldenburg commented 4 years ago

Calling remoteScript fails when ScriptController calls filemtime on the URL instead of the file (the same way script and style fail).

We could move this into a package. We haven't separated it out for simplicity as these components are only used in one project. (We're currently in the process of moving to Vapor so we had not encountered this issue previously.)

taylorotwell commented 4 years ago

Well, I mean I'm just curious why when using remoteScript you would ever hit ScriptController at all? Isn't remoteScript for links to outside URLs? And, if given a fully-qualified URL it would never hit ScriptController?

JoshOldenburg commented 4 years ago

I must have typed the wrong function during my initial tests and because of that I didn't look in the layout blade file. We've resolved this in our project by using the correct functions. Sorry for the confusion.

azimidev commented 1 year ago

@JoshOldenburg what was the correct function you used?

i currently have this and its not working with Vapor it works locally and on EC2.

Nova::script('settings', __DIR__ . '/../dist/js/tool.js');
Nova::style('settings', __DIR__ . '/../dist/css/tool.css');