我遵循了Angular 2快速入门指南,该工作正常。但我真的不喜欢他们使用的ts编译器,也不希望我的node_modules文件夹中不需要数十亿的依赖项。所以我决定从头创建我自己的angular 2项目,使用gulp将我的脚本代码的编译/ uglifying/concatting转换为1个文件。无法让Angular2 + gulp项目工作
现在,当我运行我的应用程序时,我看到“Loading ...”而不是“Hello world!”。
而且在我的控制台我得到以下错误:
GET http://localhost:3000/app/main.js 404 (Not Found) (zone.js:138)
Error: (SystemJS) XHR error (404 Not Found) loading ((index):37)
即时猜测事情错在这里与我的SystemJS和/或打字稿的编译。它正在寻找一个'main.js',即使我只有'main.ts'。
在快速入门指南中,由于编译后的打字稿,我的应用程序文件夹中确实存在'main.js'。 但是由于我使用的是gulp,我所有编译的东西都进入了一个单独的文件夹,并且有一个单独的名称,所以我没有'main.js'。
在这一点上,我无法找到任何解决方案在线,我已经开始错过Angular 1,所以任何帮助都会受到欢迎。
如果需要,我很乐意提供我的任何代码,但我的应用程序文件夹,systemjs.config.js和tsconfig.json与快速入门指南完全相同。
UPDATE
这是我的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);
感谢您的回答!我相信你是正确的,问题在于我的systemjs.config.js文件。我尝试添加地图部分,但理解错误。我改变它匹配我的appname,并使其引用我的concatted文件:'app.min.js',现在我得到的错误是404无法找到错误。就好像systemjs或zone.js正在寻找app.component和app.module文件一样。这是我没有的问题吗?由于我只有1个捆绑文件。我将编辑我的帖子,告诉你我的配置文件看起来像什么 –
值得注意的是,只要您将.ts和js文件分离出来,就会继续出现问题。继续重新映射所有错误以指向您拥有.js文件的文件夹。因为编译时这些是真正重要的。打字是简单的用户或他们认为是“简单的语言” – Bean0341
所以我需要在我的项目中存在.js文件?因为目前我编译我的脚本为JavaScript,然后在1中进行concatting和uglifying,这意味着我从来没有在我的项目中单独的.js文件。只是.ts文件和一个app.min.js –