F
Filamentโ€ข2mo 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')
),
]
);
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 ...
Jump to solution
7 Replies
Solution
Diogo Pinto
Diogo Pintoโ€ข2mo ago
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'
);
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.
ana
anaโ€ข2mo ago
So it worked? we were just using the wrong paths?
Diogo Pinto
Diogo PintoOPโ€ข2mo ago
Yes, it works perfectly, it just publishes our modified version when running filament:assets ๐Ÿ™‚
awcodes
awcodesโ€ข2mo ago
Just make sure to watch for updates in their code.
Diogo Pinto
Diogo PintoOPโ€ข2mo ago
Yeah, but this beats forking the entire thing ๐Ÿ™‚
awcodes
awcodesโ€ข2mo ago
Totally get it. Just saying. ๐Ÿ˜† Personally I would probably fork it. That gives you the control you need without unexpected bc If you composer update right now and their views change but itโ€™s still loading your script you wonโ€™t know anything changed. But if you fork and merge into your fork then youโ€™ll get a merge conflict which you can mitigate before going to production. And could even be possible that the change is worth a PR to the package itself, idk.๐Ÿคท Just something to think about.
Diogo Pinto
Diogo PintoOPโ€ข2mo ago
Yeah, thatโ€™s what Iโ€™m considering at the moment. These are minor changes but I think could benefit the whole plugin so I might just try to PR to the plugin core ๐Ÿ™‚
Want results from more Discord servers?
Add your server