Laravel Resource JS
How do I include my resource app.js file?
I've added my resource app.js file to vite.config.js but I'm not sure how to setup and to be able to be included in my Filament apps.
Do I need to use
Filament::registerScripts([])
?20 Replies
yeah you need to register it as a script
I tried but I encountered
Cannot use import statement outside a module
doesnt sound like a filament problem, just something wrong with what you put in the js file
here is the snippet inside my app.js
here is my
vite.config.js
file.
Did you just register
resources/js/app.js
. That one wasn't touched by Vite and therefore you have imports in you JS file.
Not sure what's the right syntax here. If it's output in public/js
you should use that path.should I register the asset build output by Vite? I think the filename is changing every build?
You might get it to work with the Vite class:
$vite = app(Vite::class); $vite('resources/js/app.js);
in the Filament boot?
I think Filament need to create similar to
Filament::registerViteTheme([])
but for JS moduleCheck the source code of that method 😉 It's not much magic.
There should be a
Vite::asset('/resources/js/app.js)
nowGitHub
[9.x] Vite asset url helper by timacdonald · Pull Request #43702 · ...
When using plain Blade as your templating platform, it can be useful to still process images that are not referenced in your JS with Vite - it may even be the case that you don't have any JS an...
Thanks for the help! 🍻
Is it working?
I can see now different error response, and I see the app.js is now part of the page.
nnot use import statement outside a module (
That's the same error as before isn't it?
yeah, not sure what is wrong, with the
import
in app.jsI think you cannot register a JS module (
type="module"
) with registerScript()
.that's what I'm thinking also, that is why I'm thinking to have similar to
Filament::registerViteTheme([])
but for JS module
I'm trying to check online if there is a workaround to this hahahaMaybe use a render hook to register that file yourself
its now working, thanks!
I solved it this way, now I have a file where I can add modules used by my custom filament stuff: