1.0.7 • Published 5 years ago

auto-import-dva-model v1.0.7

Weekly downloads
2
License
ISC
Repository
github
Last release
5 years ago

auto-import-dva-model

自动加载 dva model

仿umijs的 dva model 加载规则,适用于用其他脚手架搭建的基于 webpack 的工程,需要集成 dva 时,自动加载页面级 model 及其全局 model

安装

npm install --save-dev auto-import-dva-model

目录配置

    {
        path: '/home',
        component: './Home' 或者 './Home/页面名.tsx' 诸如此类
        routes:[
            {
                path:'/home/buy',
                component: './Home/Buy'
            }
        ]
    }
    其中component的路径是相对于src/pages目录来写的
  • 全局 model:src/models/*/.(js|ts)
  • 页面 model:src/pages/*/.(js|ts)

利用 webpack 动态加载模块(import(xxx))的 magic comment 特性,实现:

  • 将所有路由页面打包到 pages.chunk.js 中
  • 将所有页面级 model 打包到 models.chunk.js 中

用法

  1. 在入口(src/index.(jsx?|tsx?))除删除原有的挂在代码,改为:
import App from './.umi/router'
App.start("#root")
  1. 修改 package.json 在原有的 npm start/build 对应的脚本命令前加上: initDva && 原有的脚本命令
1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago