Angular2 lazy loading modules: how to create a build package with SystemJS Builder?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 03:45:02

See if you can appease system.js by providing a map for the required module. So when system.js finds the path modules/FIRST-SECTION/first-section.module , you tell it : Hey , could you map this path to modules/FIRST-SECTION/first-section.module.js without screaming in the console. Hope this helps .

(function (global) {
    System.config({
        paths: {
            'npm:': './node_modules/',
        },
        map: {
            app: 'app',
            'modules/FIRST-SECTION/first-section.module':'modules/FIRST-SECTION/first-section.module.js',
          .........................
          your other mappings here
          .........................
            'lodash': 'npm:lodash/lodash.min.js',
            'jquery': 'npm:jquery/dist/jquery.min.js',
        },
        packages: {
            app: { main: './main.js', defaultExtension: 'js' },
            rxjs: { defaultExtension: 'js' },
        }
    });
})(this);
Aran Dekar

in order to have bundles work for your app, you need to define the "bundles" property for systemjs, something like this:

    if (global.ENV === 'production') {
        config.transpiler = 'typescript';
        config.map = {
            'app': 'app',
            '@angular': 'node_modules/@angular',
        };
        config.packages = {
            'app': { main: 'main.js', defaultExtension: 'js' },
            '@angular/core': { main: 'index.js' },
            '@angular/common': { main: 'index.js' },
            '@angular/compiler': { main: 'index.js' },
            '@angular/forms': { main: 'index.js' },
            '@angular/http': { main: 'index.js' },
            '@angular/platform-browser': { main: 'index.js' },
            '@angular/platform-browser-dynamic': { main: 'index.js' },
            '@angular/router': { main: 'index.js' },
        };
        config.bundles = {
            'build/scripts/app.min.js': [
                'app/modules/FIRST-SECTION/*',
                'app/modules/SECOND-SECTION/*',
                '@angular/core/index.js',
                '@angular/common/index.js',
                '@angular/compiler/index.js',
                '@angular/platform-browser/index.js',
                '@angular/platform-browser-dynamic/index.js',
                '@angular/http/index.js',
                '@angular/router/index.js',
                '@angular/forms/index.js',
            ]
        }

System.config(config);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!