@tuvmdainam/mfe-cli
v1.0.11
Published
Scaffold CLI for Micro Frontend modules
Downloads
904
Readme
@tuvmdainam/mfe-cli
CLI scaffold module cho kiến trúc Micro Frontend hiện tại.
Usage
npx @tuvmdainam/mfe-cli@latest create --name mod-payments --scope payments --port 3004
npx @tuvmdainam/mfe-cli@latest create --name mod-dynaform-builder --scope dynaform --port 9268 --host 192.168.101.15Options
--name: tên module, bắt buộc, formatmod-xxx--scope: scope Module Federation, bắt buộc--port: port dev server, bắt buộc (1024-65535)--dir: thư mục đích tạo module (mặc định là thư mục hiện tại)--host: host/IP dùng chung cho shell/backend/module (ưu tiên cao hơn default localhost)--shell-url: override URL shell khi cần tách host riêng (ví dụhttp://192.168.101.15:6978)--backend-url: override URL backend khi cần tách host riêng (ví dụhttp://192.168.101.15:6976)--public-url: override PUBLIC_URL của module khi cần tách host riêng (ví dụhttp://localhost:9268/)--install: tự chạynpm installsau khi tạo xong
Ghi chú: nếu không truyền override, CLI sẽ tạo .env theo dạng host-agnostic (APP_PROTOCOL, APP_HOST, SHELL_PORT, BACKEND_PORT, MFE_PORT). CLI cũng tự dò shell-app/.env để lấy giá trị mặc định, nếu không tìm thấy mới fallback về localhost.
Template mới cài @sth87/shadcn-design-system trực tiếp trong module để dev local thuận tiện. Entry federated dùng file side-effect-free để tránh kéo runtime/bootstrap CSS ngoài ý muốn khi mount qua shell.
Ví dụ module local gọi shell trên server IP:
npx @tuvmdainam/mfe-cli@latest create --name mod-dynaform-builder --scope dynaform --port 9268 --shell-url http://192.168.101.15:6978 --public-url http://localhost:9268/Template updates (Language Sync)
Template mfe-module-base đã được cập nhật theo mô hình i18n tập trung ở shell:
- Thêm hook
useShellI18ncho remote module:- Ưu tiên
shell/i18n - Fallback
window.__SHELL_I18N_BRIDGE__ - Fallback dictionary local ở standalone mode
- Ưu tiên
- Bổ sung typing
declare module 'shell/i18n'trongsrc/types/shell.d.ts. - App template dùng i18n cho preview warning và 403 access denied.
- Home page mẫu dùng i18n key theo namespace module scope (
__MFE_SCOPE__.*). - Tránh polling render không cần thiết trong remote i18n hook (retry có giới hạn, subscribe theo event).
Checklist cho module generate mới:
- Khai báo key trên language service theo scope module.
- Dùng
t(...)từuseShellI18ntrong UI. - Không gọi trực tiếp i18n backend từ remote.
Local test
npm run check
node bin/mfe.js create --name mod-sample --scope sample --port 3011 --dir /tmp
node bin/mfe.js create --name mod-sample --scope sample --port 3011 --host 192.168.101.15 --dir /tmpPublish (private)
- Đăng nhập private registry.
- Tăng version.
- Publish package.
- Dev module dùng
npx @tuvmdainam/mfe-cli@latest create ....
