2016-11-14 77 views
0

的东西:我要创建我的角2应用捆绑Angular2生产:GULP

该如何捆绑版本:使用咕嘟咕嘟和Maven。 gulp为html,js和css文件,Maven为war文件。我按照这个教程设置了使用哟的吞咽友好结构:https://www.npmjs.com/package/generator-angular2-typescript

我在这里遵循这个解决方案:https://stackoverflow.com/a/39561478/5655414。我可以成功捆绑我的应用程序,并从我的整个项目中创建一场战争。当我运行一饮而尽的身材,我的index.html云从这个:

<menu>Loading buttons....</menu> 
<app>Loading interface..</app> 

<script src="node_modules/core-js/client/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> 
<script src="systemjs.config.js"></script> 
<script> 
    System.import('app').catch(function(err) { console.error(err); }); 
</script> 

这样:

<menu>Loading buttons....</menu> 
<app>Loading interface..</app> 

<!-- inject:js --> 
<script src="vendors.min.js"></script> 
<script src="app.min.js"></script> 
<!-- endinject --> 

当我创建war文件,其中包含:

app.min.js && -||-.map 
config.json (my config file that bootstraps the application) 
index.html (the the updated script sources) 
styles.min.css 
vendors.min.js && -||-.map 

和部署它给jboss,下面的GET请求失败:

GET http://localhost:8080/styles.min.css 
GET http://localhost:8080/vendors.min.js 
GET http://localhost:8080/app.min.js 

这对我来说没有任何意义,因为所需的js文件显然在战争文件中。

有没有额外的东西,我的index.html需要正确处理这些包?

回答

0

啊,这个问题的答案很简单。

要记住的一件事是您生成的war文件名以及您的应用程序的baseUrl。因此,你想要匹配它们。

问题 ::在我的index.html我有以下声明

<base href="/"> 

然而,我的战争文件名为:我-ui.war 因此,404个投诉是正确的:

GET http://localhost:8080/styles.min.css 
GET http://localhost:8080/vendors.min.js 
GET http://localhost:8080/app.min.js 

相反,它们应该是:

GET http://localhost:8080/my-ui/styles.min.css 
GET http://localhost:8080/my-ui/vendors.min.js 
GET http://localhost:8080/my-ui/app.min.js 

因此,我改变了基地href到:

<base href="/my-ui/"> 

而且一切都完美无缺。