在頁面中使用以下代碼引入jquery:html
<script> window.$ = window.jQuery = require('node_modules/jquery/dist/jquery.min.js'); </script>
運行時報錯:
Uncaught Error: Cannot find module 'node_modules/jquery/dist/jquery.min.js'
這個錯誤一看就是跟路徑有關,項目中引入jquery的index.html頁面與node_modules的關係以下:
按道理index.html與node_modules在同一個目錄下,上面代碼的引入方式應該是能夠的,但是事實上electron就是沒有找到正確的node_modules目錄。
在引入jquery的地方增長「./」,其中「.」表示當前目錄,即代碼改成以下:node
<script> window.$ = window.jQuery = require('./node_modules/jquery/dist/jquery.min.js'); </script>