umijs / plugins

🍣 The one-stop shop for official Umi plugins and presets.
348 stars 238 forks source link

[plugin-dva] 权限路由依然触发history.listen,model如何按需加载 #172

Open feibi opened 4 years ago

feibi commented 4 years ago

umi2中页面model是按需加载,权限路由被拦截后,history.listen不会触发。 umi3中页面model是全量加载,权限路由被拦截后,history.listen依然触发。

hurryhuang1007 commented 4 years ago

是的,找了半天怎么按需加载, 发现好像不能啊。。

xiaohuoni commented 4 years ago

umi@3 的 model 没有按需加载

hurryhuang1007 commented 4 years ago

但是我需要这个功能, 所以umi@3有计划添加这个功能吗

xiaohuoni commented 4 years ago

@sorrycc cc

yuanguandong commented 3 years ago

其实主要是model文件虽小,但是数量非常多,首屏加载很耗时,我尝试过codesplit想把这些model合起来,但是发现这样做后虽然index.html里会在加载umi.js后加载models.js, 但页面白屏也不报错

  chunks: [ 'umi','models'],
  chainWebpack: function (config, { env }) {
    config.merge({
      optimization: {
        minimize: env === 'production',
        splitChunks: {
          chunks: 'all',
          minSize: 1,
          minChunks: 1,
          automaticNameDelimiter: '.',
          cacheGroups: {
            vendor: {
              name: 'models',
              test({ resource }: any) {
                const reg1 = /.*[\\/]model.ts/.test(resource)
                const reg2 = /.*[\\/]models\/.*\.ts/.test(resource)
                const merge = reg1 || reg2
                return merge;
              },
              priority: 10,
            },
          },
        },
      },
    });
  },
CoolBerry commented 3 years ago

same issue :(