Alpine.js mixes Vue, React, and minimalism

New JavaScript framework lets developers keep their DOM and declaratively add behavior in markup

Alpine.js mixes Vue, React, and minimalism
Thinkstock

A minimal JavaScript framework, Alpine.js, promises a blend of the reactive and declarative nature of frameworks such as Vue or React but at a lower cost in terms of learning curve or complexity. 

With Alpine.js, developers can keep their DOM and add behavior as they see fit. Using a syntax borrowed from Vue and, by extension, Angular, the framework can be used to compose JavaScript behavior directly in markup. 

The founders of the project describe Alpine.js as being akin to Tailwind, a low-level CSS framework for building custom designs. Creator Caleb Porzio said that Alpine.js offers “a bunch of power at a crazy small size with no need to NPM install.” Developers can add behavior to any website—a server-rendered Rails app, WordPress app, static marketing site, etc.—simply by adding the <script> tag.

Porzio describes Alpine.js as a nimble JavaScript Swiss army knife. The qualities he attributes to Alpine.js include:

  • Ruggedness. No virtual DOM takes over the DOM. Plus Alpine.js can be used with another library.
  • Minimalism. Alpine.js is not intended for large, single-page applications.
  • Flexibility. A separate .js file for JavaScript is not needed, although developers can have one if they want.

Having already reached 1.0 status, open source Alpine.js leverages a series of directives, such as x-data, for declaring a new component scope, and x-bind, to set the value of an attribute to the result of a JavaScript expression. A series of “magic” properties, such as $refs, for retrieving DOM elements marked with x-ref, is featured as well.

Copyright © 2020 IDG Communications, Inc.