Skip to content

How to lazyload typescirpt modules with oclazyload in AndularJs 1.5+ and ui-router? #436

@duruofei930704

Description

@duruofei930704

I am trying to lazyload some modules only when a page is visited because my main.js file is too big (3.4MB).
I am using AngularJs 1.6 (typescript), webpack, ui-router, and oclazyload.
oclazyload works for me when I use it for js libraries:

   resolve: {
      deps: ['$ocLazyLoad',
        function( $ocLazyLoad ){
          return $ocLazyLoad.load([ './ckeditor/ckeditor.js']).then(function(){
             $ocLazyLoad.load(['./ckeditor/config.js', './ckeditor/styles.js'])
          });
      }]
    },

but it does not work well when I use it for module.ts files:

  resolve: {
       deps: ['$ocLazyLoad',
         function( $ocLazyLoad, $state ){
           (async () => {
             await import('../dashboard/lcses/lcses.module').then((promise)=>{
               $ocLazyLoad.inject([promise.LcsesModule]);
             });
           })();
           return;
        }]
      },

this code runs, but the the main.js file is still 3.4 MB, and it does not inject that module at the first time you visit.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions