欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

webpack ,require.ensure配合oclazyload 实现ng1模块懒加载

程序员文章站 2022-07-14 20:41:58
...
import angular from 'angular'
import 'angular-ui-router'
import 'oclazyload'
import 'bootstrap/dist/css/bootstrap.min.css'

import AppComponent from './app.component'


angular.module('app', [
	'ui.router',
	'oc.lazyLoad',
])
    .config(($stateProvider, $urlRouterProvider) => {

        $urlRouterProvider.otherwise('/')

        $stateProvider.state('search', {
            url: '/search',
            component: 'searchpageComponent',
            lazyLoad:function($q, $ocLazyLoad) {
                    let deferred = $q.defer()
                    require.ensure(['./searchPage/searchpage.js'], function() {
                        let module = require('./searchPage/searchpage.js')
                        $ocLazyLoad.load({
                            name: 'searchPage'
                        })
                        deferred.resolve(module)
                    })
                    return deferred.promise
            }

        })
    })
    .component('appCom', AppComponent)

转载于:https://my.oschina.net/boogoogle/blog/1507382