Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Latest commit

 

History

History

plugin-lazy

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

🚀 LazyPlugin

基于 React.Suspense 与 React.Lazy,提供异步组件支持。

🛠️ 使用 usage

安装 install

yarn add @spax/plugin-lazy

示例 examples

添加到 Framework

import { Framework } from "@spax/core";
import LazyPlugin from "@spax/plugin-lazy";

const options = process.env.NODE_ENV === "production"
  ? require("./config/config.prod")
  : require("./config/config.dev");

export default class MyFramework extends Framework {
  public static plugins = [
    // 作为 Framework 的静态属性
    LazyPlugin,
  ];

  public static options: any = options.default;
}

使用 Framework

import MyFramework from "./MyFramework";

const options = process.env.NODE_ENV === "production"
  ? require("./config/config.prod")
  : require("./config/config.dev");

new MyFramework({
  ...options.default,
  blocks: [
    import("./blocks/home"),
    // 404
    {
      path: "*",
      lazy: () => import("./components/NotFound"),
    },
  ],
}).mount();