【发布时间】:2021-08-01 04:55:42
【问题描述】:
我正在尝试使我的 Electron 应用程序与最新版本的 jQuery、Popper 和 Bootstrap 一起工作。不幸的是,在 index.html(渲染器进程)的 <head> 部分中引用 jQuery、Popper 和 Bootstrap 或“要求”它们都不起作用。
我试过了(选项 1):
<script src='./node_modules/jquery/dist/jquery.min.js'></script>
<script src='./node_modules/@popperjs/core/dist/cjs/popper.js'></script>
<script src='./node_modules/bootstrap/dist/js/bootstrap.min.js'></script>
<link rel='stylesheet' type='text/css' media='screen' href='./node_modules/bootstrap/dist/css/bootstrap.min.css'>
我尝试了(选项 2):
<script>let $ = require('jquery');</script>
<script>require('popper.js');</script>
<script>require('bootstrap');</script>
<link rel='stylesheet' type='text/css' media='screen' href='./node_modules/bootstrap/dist/css/bootstrap.min.css'>
无论如何,如果可能的话,我想维护nodeIntegration: false。因此,我更喜欢第一个选项(没有require)。
我收到这些错误(选项 1):
未捕获的 ReferenceError:“popper.js”中未定义导出 ...
index.html:85 Uncaught ReferenceError: $ is not defined ...
我得到了错误(选项 2):
未捕获的错误:找不到模块“popper.js” ...
jQuery.Deferred 异常:$(...).tooltip 不是函数 TypeError: $(...).tooltip 不是函数 ...
TypeError: $(...).tooltip 不是函数 ...
这些是我正在使用的 npm 包:
@popperjs/core": "^2.9.2"
"bootstrap": "^5.0.0"
"electron": "^12.0.7"
"jquery": "^3.6.0"
在我的 Electron 应用程序中包含 Bootstrap 5.0(包括所需的“包”jQuery 和 Popper)是否有任何“最佳实践”方式?
PS:我在网上找到了很多教程和提示,但我发现的方法似乎都不适用于最新版本的 Bootstrap 等。
【问题讨论】:
标签: jquery electron bootstrap-5 popper.js