2016-11-14 56 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/"> 

而且一切都完美無缺。