jquery - 使用 jQuery 和 Popper.js (svelte) 引导
问题描述
我想将带有 jQuery 和 Popper.js 的 Bootstrap 4 添加到 RollupJS。
如何将它们添加到捆绑器?
我也在使用 Svelte 汇总模板。
解决方案
如果我对您的理解正确,您正在使用默认的 Svelte Rollup 模板(可能通过npx degit sveltejs/template
),并且您希望在项目中添加对 Bootstrap 的支持。
如果是这样的话,那我认为应该是……
npm i bootstrap
npm i jquery
npm i popper.js
npm i --save-dev rollup-plugin-css-only
在您的rollup.config.js
中,添加:
import css from 'rollup-plugin-css-only';
与其他进口产品一起位于顶部。此外,在plugins
数组中,添加:
plugins: [
...
production && terser(),
css({ output: 'public/build/extra.css'})
],
在src/main.js
添加进口:
import 'bootstrap';
import 'bootstrap/dist/css/bootstrap.css';
并public/index.html
添加一个指向汇总生成的 extra.css 的链接:
<link rel='stylesheet' href='/build/extra.css'>
尽管我没有使用 jquery 或 popper.js,但至少可以通过汇总让引导程序为我工作。事实上,我在搜索相反的问题时发现了这个问题——How to use rollup with bootstrap without required jquery and popper.js。
请记住,您需要重新启动开发服务器,因为自动重新加载对 rollup.config.js 的更改不起作用。
推荐阅读
- flutter - Flutter + GetX StateManagement 访问数据的问题
- flutter - vscode上的Flutter 2.5格式奇怪
- javascript - Netlify 错误混合内容,该页面通过 HTTPS 加载,但请求的 HTTP 不安全脚本
- outlook - 更改订阅日历的位置以便更新
- python-3.x - 强制子类的重写方法由 mypy 具有相同的类型签名
- laravel-livewire - 为什么 AppHeader 组件的方法不会在发出时触发?
- apache-spark - 在 lambda 中使用 pyspark sql 函数导致 pickle 错误
- flutter - 如何在 HorizontalPicker Flutter 中显示来自 JSON 的时间?
- amazon-web-services - 如果我使用 ECR 映像/容器,我的 AWS Lambda 函数的冷启动会需要更长时间吗?
- azure - 了解 Azure Web App 日志文件输出中的 HTTP 错误