Rea*_*ues 7 javascript angular
所以我正在开发一个Angular2应用程序,只是通过引导Angular2,我发送了超过250个请求,几乎每个@angular/core节点模块包中的js文件:
具体来说,一切似乎都是从中导入的zone.js:101.这是我的应用程序入口点,只是为了证明我没有做任何不寻常的事情:
import { bootstrap } from '@angular/platform-browser-dynamic';
import { LiveComponent } from './components/live.component';
bootstrap(LiveComponent);
Run Code Online (Sandbox Code Playgroud)
这是我的HTML:
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="js/systemjs.config.js"></script>
<script>
System.config({
defaultJSExtensions: true
});
System.import('js/angular2/main').catch(function(err){ console.error(err); });
</script>
Run Code Online (Sandbox Code Playgroud)
这是systemjs.config.js:
(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'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { defaultExtension: 'js' },
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/testing',
'@angular/upgrade',
];
// 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);
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?
该设置仅用于开发.对于生产,您应该创建一个包.SystemJS具有SystemJS Builder.
JSPM将为您提供更多选择.
编辑回答你的评论:
是的,这是一个构建步骤.该种子项目使用gulp,TypeScript,TSLint,SystemJS和JSPM来构建前端.它为开发构建和生产构建提供了独特的gulp配置.
此外,在该种子项目中,您将看到package.json dependencies部分为空.那是因为他使用JSPM(此配置)来管理依赖项.
现在,捆绑器将遵循import {} from 'dependency'您使用的代码,并且仅将捆绑包添加到实际使用的内容中.