I'm glad alternatives like Alpine exist for small sites that don't need many additional behaviours. But having used Alpine for a medium-sized art gallery website last year, I can't really recommend it for anything larger than a very simple site. The fact that all your code is scattered as strings everywhere without error checking or types makes it really hard to debug and work with long-term.For lightweight front-end tooling, nothing has unseated the ease of Preact for me.
neovive|3 years ago
I find the sweet spot for utility frameworks like AlpineJS is when used in conjunction with server-side components [1]. For example, when designing server-side Blade components, the more you can keep within the component itself (e.g. html, styles, interactivity), the easier it is to reason about and maintain the component going forward. If your x-data function becomes unwieldy, consider moving the code to a separate Javascript function that returns an object and calling that function from x-data.
Ultimately, using tools like Alpine or Tailwind is a tradeoff. My apps tends to be relatively small and only managed by myself or a small team. If you're building large, front-end heavy apps; React, Vue, Svelte, etc. are definitely a better fit.
[1] Laravel Blade Components: https://laravel.com/docs/9.x/blade#components)
freedomben|3 years ago
j45|3 years ago
sodapopcan|3 years ago
tjrDL6MjB2Zwwa|3 years ago
There are times when full-blown SPA is superior, but not nearly as often as people currently think. And the toolchains get vastly simpler when you're not doing SPA too.
quantiq|3 years ago
Alpine is just not designed with that sort of application in mind, nor should it be.
flanbiscuit|3 years ago
38.2kB Minified, 13.5kB Minified + Gzipped, https://bundlephobia.com/package/alpinejs@3.10.5
10.4kB Minified, 4kB Minified + Gzipped, https://bundlephobia.com/package/preact@10.11.3
ElFitz|3 years ago
I’m just waiting for the other shoe to drop. It can’t just be that simple, can it? There has to be a catch.
victorvosk|3 years ago
lordgroff|3 years ago
For anything even slightly more complicated we have things like Mithril or Preact, and yeah they avoid this sort of thing for a reason.
scotty79|3 years ago
The whole fight since 2000 was to avoid doing that through minimalistic templating and naming elements semantically so you can attach the logic from outside.
qbasic_forever|3 years ago
The bigger question IMHO is if you actually need a SPA. If you don't then yeah the old jquery style (now alpine.js or similar frameworks are spiritual successors) is perfectly fine.
bornfreddy|3 years ago
powersurge360|3 years ago
https://alpinejs.dev/globals/alpine-data
rosszurowski|3 years ago
I used it for more complicated components like a mobile nav with animations, and for some re-usable pieces like a subscribe form. The downside with Alpine.data is that it splits the HTML from the JS, so developing and refactoring was a bit of a pain, and caused errors because of old variables I accidentally left in the HTML (whereas Preact/TSX would give me an in-editor error).
It also didn't really mitigate the need to wire up all the pieces your data component exposes into an HTML correctly. Though, this was working inside a simple PHP-based templating engine — maybe one that supports better snippets with parameters would make that part of the experience better.
wg0|3 years ago
imacrayon|3 years ago
Semaphor|3 years ago
morpogolaghora|3 years ago
schappim|3 years ago
I'm afraid this doesn't match my experience.
All your code can be in a single file (or as many as you want) with window.app = function(){return{show:false}}
fabiospampinato|3 years ago
albertTJames|3 years ago