源碼:https://github.com/sueRimn/electron-bootstrap
當引入jQuery和bootstrap文件時,會報錯,原因是:electron 的 Renderer 端因為注入了 Node 環境,存在全局函數 require,導致jquery 內部環境判斷出現問題。
1、解決方法1:
再引入jQuery和bootstrap之前插入如下代碼:
<script> delete window.require; delete window.exports; delete window.module; </script>
2、解決方法2:
前提是你必須能npm安裝jQuery和bootstrap
先用npm安裝好bootstrap和jquery,然后使用require來調用(如果無法安裝,則加上–global參數),然后將HTML頁面里面加入如下代碼
<script> window.$ = window.jQuery = require('../node_modules/jquery/dist/jquery.min.js'); require('../node_modules/bootstrap/dist/js/bootstrap.min.js'); </script>