Describe the bug
Following the rules given to us here Other Configuration, I discovered that this doesn't load any of the plugins like datatables, date picker etc...
Is there something that was omitted there or should we just create pull request adding plugins after linking to the app.js file which per my testing works., or somehow find a way to import the enabled plugins to the js files
Expected behavior
No console errors
Actual behaviour
Inability to initialize plugins
Screenshots
If applicable, add screenshots to help explain your problem or to shown the issue.
Please, provide more details on how you are trying to load the plugins (
datatable
,date picker
). However, take into consideration that when you are using Laravel Mix, all plugins should be included using it, you can't use the plugins configuration section of theadminlte.php
file anymore.For further details, check how the
enabled_laravel_mix
option impacts on the master.blade.php file.Also, you may check this issue #1030
Yes issue #1030 sums it up
When you use mix, no plugins are loaded which is not the intended behaviour
I believe adding the plugins in the master.php file under the if block would solve this problem and prevent others from having this issue and opening PRs
Would you love me to do that for you
And keep up the good work maintaining this lovely package
I'm not sure, I always believed the idea of using
Laravel Mix
is to include all plugins into compiled files, so your blade views will only include oneJS
and oneCSS
file... I have never usedLaravel Mix
, but I think that code was created that way for some reason...Yes, it's for building up all assets into one file
But in this case, there is no way we can include some without including all plugin files which would lead to a very huge file
It would be possible if we include all plugin files and find a way to purge unused styles and scripts
This would be similar to tailwind just-in-time compilation but the build step would always be necessary which is not a problem
Unfortunately, I've searched and I haven't seen a good method of purging unused js and styles without crippling functionality
So therefore to be able to use plugins, you'd have to include the plugins files in the master blade file.
Ok, you may create a PR for this, but I will have to learn how Laravel Mix works before merging it (just to sure...). The other alternative is to use the workaround mentioned on the issue #1030 ...
The workaround requires you to add the CSS and js on all pages
Maybe explaining Mix briefly would do for you, because learning webpack and mix takes a decent amount of time
Mix uses webpack to compile and bundle defences to form static assets
Eg if I require bootstrap in my app.js file, Webpack creates the corresponding file in public/js/app.js that is using the default laravel mix configuration but no need for that now
Now what is going on here is that there is no non-hacky way to include to add the plugin js files without including each and every one
That is you'd have to require each plugin
Consider this example in app.js
We have loaded what adminlte itself requires.
Now for datatables, sweet alerts etc to work, you'd have to add some of the following
Now since we are adding the contents of these scripts into the app.js file, it would become huge
I'm talking around 6 to 15 mib. In this case, it's not worth using Mix since in a real sense we cannot selectively load what plugins we would use
That's why we just use a regular script tag to load assets like this
Now the proposed solution
In master.blade.php
This says if the laravel mix option is enabled link only the app.js file that mix created, but remember that we cannot add the plugin scripts into app.js therefore, we have to link it the regular way using
@include('adminlte::plugins', ['type' => 'js'])
Now the solution is simple
Remove the plugin include from the if block so it loads plugins in all cases
It would then look something like
Do this also for CSS and that's all
Ok @yungifez I understood the problem you are facing when using
mix
. You may create a PR for this, but I will maintain order of plugins when not usingLaravel Mix
, just to be sure nothing is broken, like this:And applying the same idea for the
css
...It's better if the scripts go down so that features like the menu works before all enabled plugins.
Putting the same condition twice in if and else is considered bad practice though ( but who cares in the real world ).
You can review the pr and edit to your taste
Yeah, but I'm not sure if order matters and plugins should be before
adminlte.min.js
. I will try the changes locally just to be sure...Okay
Happy testing😊