npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

onelaraveljs

v1.2.8

Published

OneLaravel JS Framework Core & Compiler

Readme

OneLaravelJS Framework

OneLaravelJS là thư viện lõi JavaScript dành cho các ứng dụng OneLaravel. Nó cung cấp nền tảng runtime, quản lý view, routing và khả năng tương tác hai chiều mạnh mẽ giữa Laravel Blade và JavaScript.

Thư viện này đóng vai trò là "Engine", trong khi ứng dụng Laravel của bạn cung cấp "Map" (Views và Cấu hình).


🏗 Cài đặt

Cài đặt thư viện thông qua npm:

npm install onelaraveljs

Sau khi cài đặt, bạn sẽ có quyền truy cập vào:

  • Runtime Library: Các file JS để chạy ứng dụng.
  • CLI Tools: Công cụ onejs-build để biên dịch Blade template thành JavaScript modules.

📂 Cấu trúc dự án khuyến nghị

Để OneLaravelJS hoạt động hiệu quả, dự án của bạn nên tuân thủ cấu trúc sau:

my-laravel-project/
├── build.config.json           # File cấu hình build (BẮT BUỘC)
├── package.json
├── resources/
│   ├── js/
│   │   ├── app.js              # Entry point chính
│   │   ├── build/              # Output của Webpack (Bundle)
│   │   ├── config/             # Output của Compiler (Registry maps)
│   │   ├── core/               # Output của Compiler (Proxy files)
│   │   └── views/              # Output của Compiler (Compiled View Components)
│   └── views/
│       ├── _system/            # System views required by Framework
│       └── web/                # User views

⚙️ Cấu hình (build.config.json)

Tạo file build.config.json tại thư mục gốc dự án để định nghĩa các ngữ cảnh (contexts) build:

{
    "contexts": {
        "web": {
            "sources": [
                "resources/views/_system",
                "resources/views/web"
            ],
            "output": {
                "views": "resources/js/views/web",
                "register": "resources/js/config/templates.web.js",
                "bundle": "resources/js/build/web.bundle.js"
            },
            "dist": {
                "bundle": "public/static/web/js/main.bundle.js",
                "css": "public/static/web/css",
                "assets": "public/static/web/assets"
            }
        }
    }
}

🛠 Công cụ CLI (onejs-build)

OneLaravelJS đi kèm với trình biên dịch mạnh mẽ để chuyển đổi Blade Templates thành JavaScript Components.

Các lệnh phổ biến:

Thêm vào package.json của bạn:

"scripts": {
    "build:templates": "onejs-build all",
    "build:templates:web": "onejs-build web",
    "dev:blade": "onejs-build"
}
  • onejs-build all: Biên dịch tất cả các context được định nghĩa trong build.config.json.
  • onejs-build web: Chỉ biên dịch context web.
  • onejs-build: Chạy chế độ Interactive (Menu chọn).

Cơ chế hoạt động:

  1. Đọc build.config.json.
  2. Quét các file .blade.php trong thư mục sources.
  3. Phân tích cú pháp Blade, Directives (@if, @foreach), và OneJS directives (x-data, x-bind).
  4. Sinh ra các file ES6 Module tại thư mục output.views.
  5. Tạo file Registry (templates.web.js) để map tên view sang file JS.

🚀 Sử dụng trong ứng dụng (app.js)

Tại resources/js/app.js, bạn cần kết nối Core Framework với Registry views đã được biên dịch:

import { App, viewLoader } from 'onelaraveljs';

// Import Registry đã được CLI sinh ra (thông qua Proxy hoặc trực tiếp)
// Lưu ý: ViewTemplates thường được export từ file generated resources/js/core/ViewTemplate.js
import { ViewTemplates } from './core/ViewTemplate.js'; 

// 1. Dependency Injection: Nạp danh sách views vào Core
viewLoader.setRegistry(ViewTemplates);

// 2. Khởi tạo App
// App sẽ tự động đọc window.APP_CONFIGS từ Blade để cấu hình Env, Routes...
if (window.APP_CONFIGS) {
    App.init();
}

// 3. Export global (Tùy chọn, dùng cho debug hoặc legacy scripts)
window.App = App;

🧠 Core Concepts

1. View System

OneJS coi mỗi file Blade là một Component.

  • Server: Render HTML tĩnh (SEO).
  • Client: Hydrate HTML đó thành Interactive Component.

2. ViewLoader & Registry

  • ViewLoader: Là "bộ não" tải view lười (lazy-load). Nó không biết gì về ứng dụng của bạn cho đến khi được cung cấp Registry.
  • ViewRegistry: Là "cuốn danh bạ" map tên view (web.home) tới file code (WebHome.js). File này được sinh tự động.

3. Event Service

Hệ thống Event Bus tích hợp sẵn:

import { App } from 'onelaraveljs';

// Lắng nghe
App.Event.on('cart:updated', (data) => {
    console.log('Cart count:', data.count);
});

// Phát sự kiện
App.Event.emit('cart:updated', { count: 5 });

🤝 Đóng góp & Phát triển (Development)

Nếu bạn muốn chỉnh sửa source code của chính thư viện onelaraveljs:

Cấu trúc Source:

  • bin/: Chứa file thực thi CLI.
  • scripts/: Chứa logic biên dịch (Python/Node).
    • build.py: Script chính điều phối build.
    • compiler/: Bộ biên dịch Blade sang JS (Python).
  • src/: Source code JS runtime.
    • core/: Logic cốt lõi (Router, ViewEngine...).

Quy trình phát triển:

  1. Clone repo về máy.
  2. Chạy npm install.
  3. Symlink sang dự án test (npm link hoặc chỉnh sửa trực tiếp trong node_modules để debug nhanh).
  4. Đảm bảo biến môi trường ONEJS_PROJECT_ROOT được xử lý đúng trong các script build nếu chạy thủ công.

Testing:

Kiểm tra các thay đổi bằng cách chạy build trên một dự án Laravel thực tế sử dụng thư viện này (ví dụ onelaravel).


License

MIT License.