Shuvi.js Documentation

website·Indexed 29 days ago

https://shuvijs.github.io/shuvijs.org/

A front-end application development solution featuring a runtime with routing, server-side rendering, and custom configuration via shuvi.config.ts. The documentation includes API references for interfaces like IRouter, IRouteMatch, and IViewServer, as well as guides for custom error pages and application initialization.

Tokens
49.3K
Snippets
354
Records
490
Agent score
75%

What's inside Shuvi.js

  1. Overview of Shuvi.js plugin types

    Shuvi.js uses a lifecycle hook system to allow developers to add custom behaviors. There are three types of plugins based on which part of the framework they modify:

    • corePlugin: Modifies the build process.
    • serverPlugin: Modifies the behavior of the server.
    • runtimePlugin: Modifies or extends runtime components and context.
  2. Overview of Shuvijs Framework Features

    Shuvijs is a full-stack web development framework designed for developer efficiency and performance. Key features include:

    • Rendering: Progressive support for both Client-Side Rendering (CSR) and Server-Side Rendering (SSR).
    • Performance: Compile-on-demand architecture to improve development speed.
    • Extensibility: A powerful plugin system and rich API interfaces for complex scenarios.
    • State Management: Built-in state management designed for team collaboration.
    • Isomorphism: Automatic data dehydration and hydration (water injection).
  3. Overview of Shuvijs framework features

    Shuvijs is a full-stack web development framework designed for developer efficiency and performance. Key features include:

    • Rendering: Progressive support for both Client-Side Rendering (CSR) and Server-Side Rendering (SSR).
    • Performance: On-demand compilation to improve development speed.
    • Extensibility: A powerful plugin system and rich API interfaces for complex scenarios.
    • State Management: Built-in state management designed for team collaboration.
    • Isomorphism: Automatic data dehydration and hydration (water injection).
  4. Use the internal IRequest interface

    The internal.IRequest interface represents an HTTP request within the shuvijs runtime. It extends IIncomingMessage and provides detailed information about the request URL, parameters, and headers.
    // Example of the IRequest structure
    interface IRequest extends IIncomingMessage {
      headers: IncomingHttpHeaders;
      originalUrl?: string;
      params: IParams;
      parsedUrl: UrlWithParsedQuery;
      pathname: string;
      query: ParsedQuery<string>;
      url: string;
    }
  5. JavaScript and TypeScript language feature support

    Shuvi.js supports the latest JavaScript features out of the box for files with .js, .jsx, .ts, or .tsx extensions. Supported features include ES6, Async/await (ES2017), Object Rest/Spread Properties (ES2018), Dynamic import() (ES2020), Optional Chaining (ES2020), Nullish Coalescing (ES2020), and Class Fields/Static Properties (Stage 3). TypeScript is supported built-in for both runtime and plugins.
  6. Use SWC for JavaScript and TypeScript compilation in shuvi

    shuvi has replaced Babel with the Rust-based compiler SWC to compile JavaScript and TypeScript. This change provides faster compilation speeds and an improved development experience.
  7. Use the Location<S> interface for history stack entries

    The Location<S> interface represents an entry in a history stack. It extends the Path interface and provides information about the URL path, a unique identifier for the location, and arbitrary state data. It uses a type parameter S (which extends State) to define the type of the associated state object.
    // Example of the Location interface structure
    interface Location<S extends State = State> extends Path {
      key: string;
      state: S;
      redirectedFrom?: PathRecord;
    }
  8. Understand the Shuvi.js project directory structure

    A standard Shuvi.js project follows a specific directory layout to handle routing, API endpoints, and configuration. All .js or .jsx files can alternatively be written as .ts or .tsx files.
    .
    ├── .shuvi/             # Internal temporary files (regenerated on dev/build)
    ├── dist/                # Default build output directory
    ├── public/             # Static assets (copied to output directory)
    ├── src/
    │   ├── apis/           # API handlers
    │   │   ├── */
    │   │   │   ├── index.js
    │   │   │   └── *.js
    │   │   ├── index.js
    │   │   └── *.js
    │   ├── pages/          # Page components and route middlewares
    │   │   ├── */
    │   │   │   ├── index.jsx
    │   │   │   ├── *.jsx
    │   │   │   └── _middlewares.js
    │   │   ├── index.jsx
    │   │   ├── *.jsx
    │   │   └── _middlewares.js
    │   ├── app.jsx         # Root component wrapping all routes
    │   ├── error.js        # Error handling
    │   ├── runtime.js      # Runtime configuration
    │   ├── server.js       # Server configuration
    │   ├── document.js     # Server-side HTML generation logic
    │   └── document.ejs    # Basic HTML template
    └── shuvi.config.js     # Project configuration file