2016-07-05 40 views
0

該項目在使用CDN引用但不使用腳本引用時運行。我已檢查並且正確的文件被Gulp複製到wwwroot文件夾。使用ASP.NET Core的systemjs.config.js中的Angular 2 RC 4 rxjs。錯誤不明顯使用CDN

systemjs.config.js

這工作:

(function (global) { 

var ngVer = '@2.0.0-rc.4'; 
var routerVer = '@3.0.0-beta.1'; 
var formsVer = '@0.2.0'; 

var map = { 
    'app': 'app', 
    '@angular': 'https://npmcdn.com/@angular', 
    '@angular/router': 'https://npmcdn.com/@angular/router' + routerVer, 
    '@angular/forms': 'https://npmcdn.com/@angular/forms' + formsVer, 
    'rxjs': 'https://npmcdn.com/[email protected]', 
    'ts': 'https://npmcdn.com/[email protected]/lib/plugin.js', 
    'typescript': 'https://npmcdn.com/[email protected]/lib/typescript.js' 
}; 

var packages = { 
    'app': { main: 'main.ts', defaultExtension: 'ts' }, 
    'rxjs': { defaultExtension: 'js' } 
}; 

var ngPackageNames = [ 
    'common', 
    'compiler', 
    'core', 
    'http', 
    'platform-browser', 
    'platform-browser-dynamic', 
    'upgrade' 
]; 

ngPackageNames.forEach(function (pkgName) { 
    map['@angular/' + pkgName] = 'https://npmcdn.com/@angular/' + pkgName + ngVer; 
}); 

ngPackageNames.forEach(function (pkgName) { 

    packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; 
}); 

packages['@angular/router'] = { main: 'index.js', defaultExtension: 'js' }; 

packages['@angular/forms'] = { main: 'index.js', defaultExtension: 'js' }; 

var config = { 
    transpiler: 'ts', 
    typescriptOptions: { 
     tsconfig: true 
    }, 
    meta: { 
     'typescript': { 
      "exports": "ts" 
     } 
    }, 
    map: map, 
    packages: packages 
}; 

System.config(config); 

})(this); 

這段代碼不起作用:

var map = { 
    'app': 'app', 
    '@angular': 'https://npmcdn.com/@angular', 
    '@angular/router': 'https://npmcdn.com/@angular/router' + routerVer, 
    '@angular/forms': 'https://npmcdn.com/@angular/forms' + formsVer, 
    'rxjs': 'node_modules/rxjs', 
    'ts': 'https://npmcdn.com/[email protected]/lib/plugin.js', 
    'typescript': 'https://npmcdn.com/[email protected]/lib/typescript.js' 
}; 

我已經配置我咕嘟咕嘟文件複製依賴關係:

gulpfile.js

var gulp = require('gulp'); 
gulp.task('copy', function() { 
gulp.src('./node_modules/core-js/**/*.js') 
    .pipe(gulp.dest('./wwwroot/node_modules/core-js')); 
gulp.src('./node_modules/@angular/**/*.js') 
    .pipe(gulp.dest('./wwwroot/node_modules/@angular')); 
gulp.src('./node_modules/zone.js/**/*.js') 
    .pipe(gulp.dest('./wwwroot/node_modules/zone.js')); 
gulp.src('./node_modules/systemjs/**/*.js') 
    .pipe(gulp.dest('./wwwroot/node_modules/systemjs')); 
gulp.src('./node_modules/reflect-metadata/**/*.js') 
    .pipe(gulp.dest('./wwwroot/node_modules/reflect-metadata')); 
gulp.src('./node_modules/rxjs/**/*.js') 
    .pipe(gulp.dest('./wwwroot/node_modules/rxjs')); 
gulp.src('./typings/**/*.*') 
    .pipe(gulp.dest('./wwwroot/typings')); 
}); 
gulp.task('default', ['copy']); 
+0

您需要爲包中的rxjs提供主文件 – Siraj

+0

您能告訴我主要應該是什麼?這個作品: 'rxjs':{main:'\ *。\ *',defaultExtension:'js'} 我不知道主要應該是什麼。 – Mark

+0

瀏覽到node_modules以識別主文件。大多數任何庫的package.json都有主屬性來幫助識別它。對於Rx,我使用/bundles/Rx.umd.js。注意這將加載完整的Rxjs – Siraj

回答

0

這個錯誤似乎是:

'app': { main: 'main.ts', defaultExtension: 'ts' }, 

它應該是:

'app': { main: 'main.js', defaultExtension: 'js' }, 

這工作:

(function (global) { 

var map = { 
    'app': 'app', 
    '@angular': 'node_modules/@angular', 
    'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api', 
    'rxjs': 'node_modules/rxjs' 
}; 

var packages = { 
    'app': { main: 'main.js', defaultExtension: 'js' }, 
    'rxjs': { defaultExtension: 'js' }, 
    'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' } 
}; 

var ngPackageNames = [ 
    'common', 
    'compiler', 
    'core', 
    'forms', 
    'http', 
    'platform-browser', 
    'platform-browser-dynamic', 
    'router', 
    'router-deprecated', 
    'upgrade' 
]; 

function packIndex(pkgName) { 
    packages['@angular/' + pkgName] = { main: 'index.js', defaultExtension: 'js' }; 
} 

function packUmd(pkgName) { 
    packages['@angular/' + pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' }; 
} 

var setPackageConfig = System.packageWithIndex ? packIndex : packUmd; 

ngPackageNames.forEach(setPackageConfig); 

var config = { 
    map: map, 
    packages: packages 
}; 

System.config(config); 

})(this);