问题描述
还有var map,packages,var config在这里做什么?我有点困惑他们做任何配置吗?我看到了每个项目,并且发现他们到处都放了这个文件.这个功能做什么?
And also what does var map,packages, var config do here I am bit confused heredo they do any config.I seen every project and I found everywhere they put this file. What this function do?
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'rxjs': 'node_modules/rxjs',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'@angular': 'node_modules/@angular',
'primeng': 'node_modules/primeng'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'boot.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { defaultExtension: 'js' },
'primeng': { defaultExtension: 'js' }
};
var packageNames = [
'@angular/common',
'@angular/compiler',
//
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function(pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
map: map,
packages: packages
}
// filterSystemConfig - index.html's chance to modify config before we register it.
if (global.filterSystemConfig) { global.filterSystemConfig(config); }
System.config(config);
})(this);
推荐答案
它允许配置SystemJS来加载使用TypeScript编译器编译的模块.对于匿名模块(每个JS文件一个模块),它允许将模块名称映射到实际包含模块JavaScript代码的JS文件.
It allows to configure SystemJS to load modules compiled using the TypeScript compiler. For anonymous modules (one module per JS file), it allows to map the name of modules to JS files that actually contains the module JavaScript code.
这里是一个样本.如果我尝试导入名为app/test
的模块,SystemJS将执行以下操作:
Here is a sample. If I try to import the module named app/test
, SystemJS will do:
- 尝试查找预注册的模块(使用
System.register('app/test', ...
- 如果不是,它将检查其配置以构建请求以执行以加载相应文件:
-
app
有一个map
条目 - 在
app
中有一个packages
条目,其中defaultExtension
=js
- Try to find a preregistered module (with
System.register('app/test', ...
- If not, it will look into its configuration to build the request to execute to load the corresponding file:
- there is a
map
entry forapp
- there is a
packages
entry forapp
withdefaultExtension
=js
这篇关于在angular 2打包结构中,systemjs.config.js做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- there is a
-