⚠️ The development of this project has shifted to create-unit repository.
Old README file
Unit.js is a lightweight JavaScript UI framework designed to bring focus, simplicity, and enhanced developer productivity to your projects. Inspired by Alpine.js and powered by Vite, Unit.js encourages a streamlined development experience with a unique approach to components.
Define state and components once, reuse them wherever.
Note:
⚠️ This project is still under development.
-
Focus on Simplicity: Unit.js embraces simplicity as a core principle, making it easy for developers to create and manage UI components effortlessly.
-
File-based Components: Components in Unit.js are represented as files ending with the
.unit
extension. This convention simplifies organization and encourages a modular structure in your project. You can import.unit
files into another.unit
file. -
Alpine.js Syntax: Leverage the expressive syntax of Alpine.js within your components. Enjoy the power of declarative programming without unnecessary complexity.
-
HTML Build Output: Generate a fully-rendered page at build time (Alpine.js will be injected).
-
Reactive by Default: Components contain plain HTML code with Alpine.js syntax that is reactive during runtime.
Note: Unit.js is powered by Vite and so most features can be used directly in your project for example asset handling.
Unit.js maintains it's major releases in branches of this repository:
-
master
: default branch for next version development containing latest features. -
v1
: latest version
Note: Branches named
v*
for example; v1, v2, ... are branches containing specific stable versions of Unit.js
Basic understanding of HTML, CSS, JavaScript, Alpine.js and Node.js (npm and/or pnpm) is required.
-
Installation: Install Unit.js using your preferred package manager. For a different version, say
v2
, changev1
tov2
in the following command.npx degit github:henryhale/unit.js#v1 my_app cd my_app npm install # pnpm install
-
Create Your First Component: Within your
src/pages/
folder, simply create a new file with the.unit
extension, import it into thesrc/pages/index.unit
and you're ready to start building your UI component using Alpine.js.<!-- hello.unit --> <div x-data="{ message: 'Hello, Unit.js!' }"> <p x-text="message"></p> </div>
<!-- index.unit --> import Hello from "hello.unit"; <Hello />
Note: Feel free to scrap out stuff that you don't need for example .github/workflow/...
-
Run the Development Server: Start the development server to see your changes in real-time.
npm run dev # pnpm dev
-
Build for Production: When you're ready to deploy your application, build for production to optimize and minimize your code.
npm run build # pnpm build
-
Deployment: After building your project, production files exist in the
dist
folder at the root of your project.
.vscode/
: contains settings and recommended extensions for Visual Studio Code userssrc/
: all your project source files heresrc/components/
: contains reusable .unit filessrc/data/
: contains composable and state scriptssrc/pages/
: contains only .unit files for corresponding html pagessrc/public/
: contains assets to be served at the root like favicon.pngsrc/template.html
: used to generate html pages from every .unit file insrc/pages/
folder on build timesrc/main.js
: common script for all pages place in thesrc/template.html
. For a different script per page, create another script and add a script tag in the corresponding .unit file under thesrc/pages/
foldersrc/style.css
: Shared CSS styles
Contributions are welcome to make Unit.js even better! Feel free to open issues or submit pull requests.
Unit.js is released under the MIT License.
Copyright © 2023 Henry Hale
Enjoy the focus, simplicity, and increased productivity that Unit.js brings to your UI development!