Modern.js Documentation

repository·main·Indexed 26 days ago

https://github.com/web-infra-dev/modern.js

A progressive React-based web framework designed to simplify modern web development with built-in solutions for routing, data fetching, and state management. It features a high-performance ecosystem powered by Rspack, including tools like Rsbuild, Rspress, and Rslib. The framework supports Client-Side Rendering (CSR), Server-Side Rendering (SSR) with streaming mode, and Module Federation.

Tokens
208.1K
Snippets
644
Records
1.3K
Agent score
88%

What's inside Modern.js

  1. Introduction to @modern-js/plugin-i18n

    main

    @modern-js/plugin-i18n is the internationalization plugin for Modern.js. It is built on top of i18next and react-i18next to provide a seamless i18n experience within the Modern.js framework.

    Key features include:

    • Framework Integration: Handles SSR (Server-Side Rendering) language passing and automatic route prefix handling.
    • Core Translation: Leverages i18next for functions like t(), interpolation, plurals, and namespaces.
    • React Integration: Leverages react-i18next to provide React components and Hooks (e.g., useTranslation) that work with the React lifecycle.
  2. Overview of Rspack in Modern.js

    main
    Modern.js supports Rspack, a high-performance JavaScript bundler written in Rust. Rspack is designed to be a drop-in replacement for webpack, offering strong compatibility with the webpack ecosystem while providing significantly faster build speeds (benchmarks suggest 5-10x better compilation performance) due to its Rust-based implementation, parallel architecture, and incremental compilation features.
  3. Overview of Modern.js

    main
    Modern.js is a progressive Web development framework based on React. It provides a comprehensive set of configurations and tools required for React applications, including built-in optimizations and features for common requirements such as routing, data fetching, and state management. It is designed to allow developers to build UIs with React while incrementally adopting framework features to solve application needs.
  4. Introduction to Modern.js

    main

    Modern.js is a progressive web framework based on React designed to provide high-performance development and user experiences. It is built to support both Client-Side Rendering (CSR) and Server-Side Rendering (SSR) as first-class citizens.

    Key features include:

    • Rust Bundler: Uses Rsbuild/Rspack for high-speed compilation.
    • Progressive Development: Start with streamlined templates and gradually enable features via generators.
    • Isomorphic Development: Unified development and production environments for CSR and SSR, with API service calls treated as functions as interfaces.
    • Convention Routing: Supports file-based routing for rapid application setup.
  5. Understand the default output directory structure

    main

    By default, Modern.js compiles files into a dist directory at the project root. The structure is organized by file type:

    • HTML files: Output to dist/html/[name]/index.html.
    • JS files: Output to dist/static/js/[name].[hash].js.
    • CSS files: Output to dist/static/css/[name].[hash].css.
    • License files: Generated alongside JS files with a .LICENSE.txt suffix.
    • Source Map files: Generated alongside JS and CSS files with a .map suffix.

    [name] refers to the entry name (e.g., index, main), and [hash] is a content-based hash.

  6. Understand Modern.js configuration types

    main

    Modern.js uses three distinct types of configuration depending on when and where they are applied:

    1. Compile configuration: Configures the build process. Can be defined in modern.config.(ts|js|mjs) at the project root or in the package.json file under the modernConfig field.
    2. Runtime configuration: Configured in src/modern.runtime.(ts|js|mjs).
    3. Server Runtime configuration: Configured in server/modern.server.(ts|js|mjs).

    Note: Do not configure the same item in both package.json and modern.config.ts simultaneously, as this will cause conflicts and warnings.

  7. Understand SSG (Static Site Generation)

    main
    SSG (Static Site Generation) is a rendering method where web pages are pre-rendered as static HTML files during the build process. These files can be served directly from a CDN or static hosting service. While SSG offers faster loading speeds and lower server overhead than SSR, it is less suitable for sites requiring real-time dynamic content updates.
  8. Use Rspress for documentation sites

    main

    Rspress is a framework designed for building high-performance documentation sites. Key features include:

    • Rspack-based build: Extremely fast project builds and HMR (Hot Module Replacement).
    • MDX Support: Allows embedding React components and JSX syntax directly within Markdown files.
    • Full-text Search: Built-in search functionality powered by FlexSearch.
    • Internationalization (i18n): Supports multi-language documentation switching and multi-language content search.
    • Customizable Themes: Includes a default theme that can be extended or replaced with a custom one.
    • Plugin System: Provides rich plugin hooks for framework customization.

    Note: Rspress is currently in beta. You can find the source code in the Rspress repository.

  9. Use Modern.js Module for npm package development

    main

    Modern.js Module is a specialized toolset for developing, debugging, and publishing npm packages. It provides a professional workflow with the following core capabilities:

    • Build Capabilities: An esbuild-based build tool that supports type generation and highly customizable build outputs.
    • Debugging Capabilities: Integration with Storybook to test component functionality and verify the usability of build artifacts.
    • Version Management: Uses Changeset to provide commands for managing the entire lifecycle from development to release.
    • Extensibility: A plugin mechanism with rich Hooks to extend debugging capabilities or customize development workflows.
  10. Understand Page Entries in Modern.js

    main
    An Entry is the starting module of a page. In Modern.js, each entry corresponds to an independent page and a server-side route. Modern.js can automatically determine entries based on directory conventions or allow manual customization via configuration. Many features, such as page titles, HTML templates, meta information, and SSR/SSG settings, are configured on a per-entry basis.