2017-06-01 40 views
0

我在運行MS IE 10/11的某些組件時遇到問題。 根據Angular.io的這個arcticle(https://angular.io/docs/ts/latest/guide/browser-support.html),我需要導入一個外部腳本。Angular 2 import node_modules not adding to build

<script src="node_modules/core-js/client/shim.min.js"></script> 

這一點我放置在我的index.html

<!doctype html> 
<html> 
    <head> 
     <meta charset="utf-8"> 
     <title></title> 
     <base href="/"> 
     <link rel="icon" type="image/x-icon" href="/assets/favicon.ico"> 
     ... 
     <script src="../node_modules/core-js/client/shim.min.js"></script> 
    </head> 
    <body> 
     <app-root></app-root> 
    </body> 
</html> 

但是,當我建立生產它不將其添加到構建,它只是留下它在腳本中有結束未找到錯誤運行應用程序時。

我可能錯過了一些東西,但我不知道是什麼。

在此先感謝!

+0

Angular不會讀取您的index.html文件以找出需要捆綁的依賴關係。當您進入構建階段時,index.html文件基本未變。您必須通過適當的系統通道將其指定爲依賴項。但是,要做到這一點的細節實際上可能會發生很大的變化,這取決於您的構建如何管理。你在使用角度cli嗎?你有沒有下載一個角度種子項目(可能與webpack或systemjs)?基本上,有多種方式來管理構建過程,答案取決於構建的管理方式。 –

+0

我在webpack中使用Angular Cli,它是從頭開始構建的大型應用程序。 – Peter

回答

0

在你.angular-cli.json文件中找到(或創建)的定義爲您的應用程序的"scripts"鍵,以及陣列中添加一個條目爲shim.js腳本,例如:

"scripts": [ 
    "../node_modules/core-js/client/shim.min.js" 
], 

重新啓動ng serve或重建你的捆綁,你應該很好去。

希望這會有所幫助!

0

您需要在angular-cli.json文件中添加CSS文件和JS文件。如果您在這種情況下未使用angular-cli,則需要在您使用的構建工具中進行配置