2016-10-24 35 views
1

我正在開發一個帶有Electron和Angular2的桌面應用程序(使用Angular-Cli)。Angular-CLI for Electron應用程序

我想用引導所以在我的角cli.json,我添加所需的腳本文件到應用[0] .scripts中像下面這樣:

"scripts": [ 
    "../node_modules/jquery/dist/jquery.min.js", 
    "../node_modules/bootstrap/dist/js/bootstrap.min.js", 
    "../node_modules/toastr/build/toastr.min.js" 
    ], 

當我運行的Web應用程序(使用ng服務),一切工作正常。但是當我使用Electron運行應用程序(首先構建ng,然後從/ dist運行Electron)時,我遇到以下錯誤: 未捕獲的錯誤:Bootstrap的JavaScript需要jQuery。角2部分工作正常,路由工作,視圖呈現正確等。

當我調查scripts.bundle.js,這些第三方庫包括在內。但Bootstrap代碼在JQuery之前。這就是我看到Electron出現錯誤的原因嗎?

+0

jQuery有在電子使用一種特殊的方式,也許這是你的問題。在電子jquery必須注入使用'require()' –

+1

感謝您的洞察力。您的回覆引導我轉到另一篇文章,幫助我解決問題。 http://stackoverflow.com/questions/32621988/electron-jquery-is-not-defined – Iris

回答

1
<script> 
    try { 
     window.nodeRequire = require; 
     delete window.require; 
     delete window.exports; 
     delete window.module; 
    } catch (e) { 
    } 
</script> 

添加到這個index.html的

+0

謝謝,它可以幫助我。但它不會破壞別的東西嗎?你能解釋它是如何解決這個問題的? –

0

對我來說它的工作同時安裝jQuery和@類型/ jQuery和將它們放置在這個順序。

"scripts": [ 
    "../node_modules/jquery/dist/jquery.min.js", 
    "../node_modules/bootstrap/dist/js/bootstrap.min.js" 
], 

〜HTH

相關問題