1

我正在使用 Angular2 教程项目https://angular.io/docs/ts/latest/tutorial/并使用 SystemJS Builder 进行应用程序捆绑。但是,我正在为生成的捆绑代码注册模块中的路径而苦苦挣扎。这是我的文件夹结构:

wwwroot
|-dist
  |-configs
  |  |-systemjs.config.js
  |    
  |-js
  | |-bundle.js //generated output bundle
  |
  |-main.js
  |-app.module.js
  |-app.component.js
......................

systemjs.config.js 文件:

(function (global) {
    System.config({
        baseURL:'wwwroot',
        paths: {
            // paths serve as alias
            'res:': 'lib/',
            'ng:': 'lib/@angular/'
        },
        // map tells the System loader where to look for things
        map: {
            // !!! the app is within the dist folder !!!
            'app': 'dist',
            // angular bundles
            '@angular/core': 'ng:core/bundles/core.umd.js',
            // other Angular 2 stuff...
            '@angular/upgrade': 'ng:upgrade/bundles/upgrade.umd.js',
            // other libraries
            'rxjs': 'res:rxjs',
            'angular2-in-memory-web-api': 'res:angular2-in-memory-web-api',
        },      

        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                //app entry point
                main: './main.js',
                format: 'register',
                defaultExtension: 'js'    
            },
            rxjs: {
                defaultExtension: 'js'
            },
            'angular2-in-memory-web-api': {
                main: './index.js',
                defaultExtension: 'js'
            }
        }
    });
})(this);

吞咽任务:

var systemjsBuilder = require('systemjs-builder');

gulp.task('bundle-app', function () {

var builder = new systemjsBuilder('', 'wwwroot/dist/configs/systemjs.config.js');

return builder
    .bundle('wwwroot/dist/**/*', PATH.root + PATH.dist + '/js/bundle.min.js', {
        minify: false,
        mangle: true
    })
    .then(function () {
        console.log('Build complete');
    })
    .catch(function (err) {
        console.log('Build error');
        console.log(err);
    });

});

在生成的捆绑文件中,所有通过 注册的模块System.registerDynamic('wwwroot/dist/main.js',...)都不起作用。但是,如果我从注册路径中手动删除所有'wwwroot/'内容,则应用程序开始工作(它映射到systemjs.config.js文件中的“dist”)。

我应该如何配置构建器(或系统配置文件)以省略'wwwroot'文件夹添加或正确解析?任何建议将被认真考虑。

谢谢!

4

1 回答 1

1

终于找到了!只需要:

  • 将根基 URL 添加到构建器实例,例如new systemjsBuilder('wwwroot', 'wwwroot/dist/configs/systemjs.config.js');
  • 更改.bundle('wwwroot/dist/**/*',....bundle('[dist/**/*]', ...(方括号删除依赖项)
  • systemjs.config.js文件中将应用程序包格式从更改registercjs(我的 JS 模块为 CommonJS 格式)或完全删除格式以启用模块自动检测。
于 2016-10-19T19:09:32.177 回答