【发布时间】:2017-04-04 23:18:18
【问题描述】:
我遵循了 Angular 2 快速入门指南,它运行良好。但我真的不喜欢他们使用的 ts 编译器,也不希望我的 node_modules 文件夹中有数十亿个我不需要的依赖项。所以我决定我要使用 gulp 从头开始构建我自己的 angular 2 项目,用于将我的 typescript 代码编译/丑化/合并到 1 个文件中。
现在,当我运行我的应用程序时,我看到“正在加载...”而不是“Hello world!”。
在我的控制台中,我收到以下错误:
GET http://localhost:3000/app/main.js 404(未找到)(zone.js:138)
错误:(SystemJS) XHR 错误 (404 Not Found) loading ((index):37)
我猜我的 SystemJS 和/或 typescript 的编译出了点问题。即使我只有一个“main.ts”,它也在寻找一个“main.js”。
在快速入门指南中,我的 app 文件夹中确实有一个“main.js”,这是编译后的打字稿的结果。 但是由于我使用的是 gulp,所以我所有编译的东西都放在一个单独的文件夹中,具有单独的名称,所以我没有“main.js”。
此时我在网上找不到任何解决方案,而且我已经开始怀念 Angular 1,因此我们非常欢迎任何帮助。
如果需要,我很乐意提供我的任何代码,但我的 app 文件夹 systemjs.config.js 和 tsconfig.json 与快速入门指南完全相同。
更新
这就是我的 systemjs.config.js 的样子,正如我所料,这就是问题所在。它似乎在寻找 .module 和 .component 文件,但我只有 1 个文件:包含所有代码的“app.min.js”。这是错的吗?
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'dist/app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/router/upgrade': 'npm:@angular/router/bundles/router-upgrade.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './app.min.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
【问题讨论】:
标签: angular installation dependencies