Laravel Mix for Kirby

Hi,

I’ve just created my first plugin: Laravel Mix for Kirby

This is basically just a mix() helper function for CSS and JS files versioned by Laravel Mix. I immediately fell in love with Laravel Mix and wanted to have the mix() function inside my Kirby snippets.

As this is my first plugin I would love to get some feedback. I’m actually more of a frontend developer and not that experienced with this kind of stuff. Any kind of help would be very appreciated :slight_smile:

Have a nice day!

2 Likes

Great plugin @RobertC! I also use Laravel and am huge fan of its ecosystem. It’ll be great to use Laravel Mix with Kirby.

I just followed the steps in the readme to install your plugin and it worked well. Kudos for adding detailed setup instructions!

1 Like

Thanks @pedroborges! I’m glad that the instructions were helpful and that everything is working :wink:

It’s not an issue at all, but you’re using config identifiers like this:

  • mixManifestPath
  • mixAssetsPath

while the Kirby convention would be more like:

  • mix.manifest.path
  • mix.assets.path

or probably just:

  • mix.manifest
  • mix.assets

Thanks for the tip. I will change that immediately.

Maybe it’s not always needed but because Kirby have a whole lot of own options I usually prefix my options like this:

c::get('plugin.mix.manifest.path');

The Kirby options seems to be growing all the time and it can be hard to predict what is coming next.

Sometime I suggested that Kirby should use a prefix instead like kirby.css.handler instead of css.handler but I got voted down on that one.

Thanks for the hint, @jenstornell. I haven’t thought about that to be honest. Although I guess (or wish) that if Kirby uses that option in the future it’ll mean that Laravel Mix will be included as a default and thus making my plugin obsolete. But that’s probably never gonna happen. Still, one can dream :wink:

Hi @RobertC

Do you plan a Kirby 3 - Version release of your
“Laravel Mix for Kirby” - PlugIn?

Saludos, Funkybrotha

Funny that you ask, @funkybrotha. I’m working on it right now :smiley:

Hi @RobertC

G R E A T !

:wink:

Saludos, Funkybrotha

@funkybrotha Unfortunately I can’t get it to work. I’ve never developed a Composer package so I have absolutely no idea where to start with this :frowning: Maybe I can continue when the plugin part of the Kirby documentation is more complete. I actually need this for my own projects, so I will definitely keep an eye on this! :slight_smile:

The composer stuff isn’t compulsory. You could get it working without all that, it just means people have to manually install it the old way by downloading it and dropping it into the plugins folder. Your plugin isn’t especially complex as far as i can tell, it just needs wrapping in the new style plugin declaration, and a small tweak to the way you get options from the config.

That day is today: :tada:

i dont wanna be a spoilsport but since laravel mix got a new version 4.0 you might need to do some more than just adding pluginkit suppor.

Hi @RobertC

No Problem… i think i’ve found a quick and “dirty”
solution for the moment.

    $json = f::read('./assets/mix-manifest.json');
    $jsonDecode = json_decode($json, true);
    $jsonItems = ($jsonDecode);
    $mixJs = $jsonItems['/js/app.min.js'];
    $mixCss = $jsonItems['/css/app.min.css'];

<link rel="stylesheet" href="assets<?php echo $mixCss; ?>" />
<script src="assets<?php echo $mixJs; ?>"></script>

My mix-manifest.json - File looks like this:

{
    "/js/app.js": "/js/app.js?id=d5af252260873add5cc2",
    "/css/app.css": "/css/app.css?id=29dacf8022d4c705552a",
    "/js/app.min.js": "/js/app.min.js?id=d5af252260873add5cc2",
    "/css/app.min.css": "/css/app.min.css?id=29dacf8022d4c705552a"
}

A well written plugin would be definitely better. :wink:

Saludos, Funkybrotha

Hey guys,

first, @lukasbestle great to hear that the docs are updated. Thanks for your great work :wink:

@bnomei I will definitely look into that and see what has to be updated. But as @jimbobrjames pointed out, the plugin is really simple — I’d say it’s the definition of “simple” — and that’s of course by design. But I still want it to behave the way one would expect it, which includes being installable any way you want.

I will get back to you as soon as I’m finished :slight_smile:

Good news, @funkybrotha, the plugin is now ready for Kirby 3 :blush: I just installed it via composer and everything is working:

composer require diverently/laravel-mix-kirby

I would love to hear from anyone using this, especially if there’s something to be fixed.

1 Like

@RobertC Good stuff! I happen to use mix too, so I will give it a try as well. But, forgive me, I don’t actually see what this plugin does, other then create a link to the JS & CSS in the template? This works just fine with the standard Kirby helpers, and Browsersync happily live reloads it after Mix compiles the code. Am i missing something? Does your plugin carry through the mix versioning?

Laravel Mix looks really handy. From what I understand though it doesn’t support file globbing. Is that true?

Not true. You can feed it as many source files as you like and it will spit them combined into one file… unless that isnt what you meant? Ive never tried to feed it something like src\js\*.js