FilamentF
Filamentβ€’15mo ago
Diogo Pinto

Override plugin's Javascript files without publishing?

Hello everyone πŸ‘‹πŸ»

I'm using some plugins, and I would like to make some modifications on some JS files.

I can publish these using filament:assets. The thing is, in the future, if I have to run that again, my modifications will be overwritten.

I was trying to replace the JS call in my AppServiceProvider, using something like:

FilamentAsset::register(
    assets: [
        AlpineComponent::make(
            id: 'global-search-modal-observer',
            path: resource_path('js/observer.js')
        ),
    ]
);


But it doesn't overrwite, even if I set a package in the register method.

Maybe I'm looking on the wrong place, so if anyone can help me, I would appreciate it!

(I considered forking the plugins, but upgrading would be a messier work)
Solution
So, the answer is quite simple:

  • Put your updated file on your resources folder (/resources/js/custom/customfile.js)
  • Register the asset with the package name in it in your AppServiceProvider
Here's my example with Global Search Modal:

FilamentAsset::register(
    assets: [
        AlpineComponent::make(
            id: 'global-search-modal-observer',
            path: resource_path('js/charrafimed/global-search-modal/components/global-search-modal-observer.js')
        ),
    ], package: 'charrafimed/global-search-modal'
);


This way, when you publish the files with filament:assets, you get your custom JS in your public folder.
Was this page helpful?